A solution given below taken from "cracking the Coding interview " book...
Solution is create a Comparator and a small change in "compare" method is that u sort the characters of that string and then compare. and just sort the arrays, using this compareTo method instead of the usual one. Arrays.sort(array, new AnagramComparator()); public class AnagramComparator implements Comparator<String> { public String sortChars(String s) { char[] content = s.toCharArray(); Arrays.sort(content); return new String(content); } public int compare(String s1, String s2) { return sortChars(s1).compareTo(sortChars(s2)); } } *Shashi Kant * ***"Think positive and find fuel in failure"* http://thinkndoawesome.blogspot.com/ *System/Software Engineer* *Hewlett-Packard India Software Operations. * On Sun, May 27, 2012 at 2:56 AM, Navin Gupta <navin.nit...@gmail.com> wrote: > @jalaj :- we will be sorting a copy of the word and then matching the > sorted_sequence with the sorted_sequence of the copy of other words. > It will still be in-place, because we are using a space of Word size where > the input is a dictionary. > This is an amortized in-place. > > -- > Navin Kumar Gupta > Computer Science & Engg. > National Institute of Technology,Jamshedpur > > -- > 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/-/n2tGzVxSLIYJ. > > 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.