What I Could possibly think of is For each string S1 that is an anagram of some string S, use Map and Store the Key Value as (S1,S). Now there is a trick here abt how to reduce Time Complexity here...
Now its easy to put all string which has correspondence S next to each other. This is Simple one. Inplace.. Hv to think abt .. I doubt, as we need some space to get the anagrams Dude.. Prem On Tue, May 22, 2012 at 5:18 PM, Ashish Goel <ashg...@gmail.com> wrote: > Write a method to sort an array of strings so that all the anagrams are > next to each other. > > What i could think of is preparing a multi linked list( multimap) whereby > the key for each string is the sorted representation of the string(eg if > string is gac, its sorted representation is acg). Walk of all lists of this > multimap to give all anagrams. > > Is there any other better solution for this problem? > Can this be done *inplace*? > > Best Regards > Ashish Goel > "Think positive and find fuel in failure" > +919985813081 > +919966006652 > > -- > 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.