changes HasAnagram to run in O(n)