Solve anagrams in O(n) time