ctci 10.2: sort an array of strings so that all the anagrams are next to each other