This can be done in O(n).. first shift all the 2's to the right side in O(n)...
then again shift 1to the right shift b efore 2's......... in O(n)... With regards, Praveen Raj DCE-IT 3rd yr 9999735993 praveen0...@gmail.com On Mon, Sep 26, 2011 at 6:23 PM, Naren s <sweetna...@gmail.com> wrote: > dutch national flag problem..search in wiki...classical. > > On Sat, Sep 24, 2011 at 9:39 AM, VIHARRI <viharri....@gmail.com> wrote: > >> You are given a string (consisting of 0's, 1's or 2's) where 0 >> represents a blue ball, 1 a >> red ball, and 2 a black ball. Using only swap operations (counting >> sort not allowed) >> rearrange the string such that all blue balls are together on one >> side, followed by all red >> balls, and then all black balls. You can iterate through the string >> only once. >> Eg 102112011 should produce 001111122 >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > > > -- > *Narayanan S,* > B.E., C.S.E., (final year), > College Of Engineering Guindy, > Anna University, > Chennai-25. > > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.