optimization in anagram