It's essentially the same as kumar's algorithm. a[n - 1] records the total number of 1's, ie. K; a[a[n-1]-1] = a[K-1] records the number of 1's in the first K elements. the difference K-a[K-1] is the number of 0's in the first K elements, to be swapped for remaining 1's.
2016-04-19 16:54 GMT+08:00 ranganath g <[email protected]>: > Hey Sachin, > > What is the correctness of your code? I mean how do you say that this is > give the right answer > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > -- __________________________________________________ -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
