How about using a hash. Hash element to its position in the array.
This way we can preserve the order.

On Sep 7, 4:33 pm, gaurav gupta <1989.gau...@googlemail.com> wrote:
> Counting Sort is a good solution. This problem is same like :
>
> you have an array 1,3,1,3,2,6,5,7,8,5,6,4,5,2 You have to arrange them such
> that all number having same value should occur together and order of
> occurrence in series should conserve. So result will be :
>
> 1,1 ,3,3,2,2,6,6,5,5,5,7,8 ,4
>
>
>
> On Sun, Sep 6, 2009 at 11:39 AM, Dufus <rahul.dev.si...@gmail.com> wrote:
>
> > How about counting sort in O(N+K) time and O(K) space.
>
> > _dufus
>
> > On Sep 6, 1:06 pm, ankur aggarwal <ankur.mast....@gmail.com> wrote:
> > > You have N balls having one of K colors. Arrange them into groups of same
> > > colors. e.g.
>
> > > RRRRRRGRG
> > > can be arranged as
> > > RRRRRRRGG (Answer)
> > > GGRRRRRRR
>
> --
> GAURAV GUPTA
> B.Tech IV Yr. , Department of Computer Science & Engineering
> IT BHU , Varanasi
> Contacts
> Phone No: +91-99569-49491
>
> e-mail :
> gaurav.gu...@acm.org
> gaurav.gupta.cs...@itbhu.ac.in

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to