Make an array of size n, and fill it with index of last 1 of corresponding
row in the matrix.. as if row 0 has 1101100 , than arr[0]=4 .
so we end up with an array containing last position of 1 in the respective
row..
lets arr[4] is like 3,2,2,1... we have to make it 1,2,2,3.. so now apply
following swap rules.
i) if by swapping two element , greater element is goin into greater
index...do the swapping else move to next as in 2 ,3 ,2 ,1 : dont swap first
2 and 3..
ii) or by swapping two element , lesser element is goin into lesser index
...
and when you reach till the end , move back.. it may require many iteration,
so use recursion.. *first forward traversing , and then backward* and front
and end of the array will be decremented by 1 in each iteration..
Please let me know if it is wrong..!
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/Nbphh8aWnTkJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.