Given two strings s and t , write a function to determine if t is an anagram of s.
What if the inputs contain unicode characters? How would you adapt your solution to such case?
Given the assumptions that the strings will only be lowercase, you can get the index of each character in the array by subtracting the
ord(char) by 97 which is the ordinal value of
a. Then you loop through one of the strings, add and then subtract each index. Finally you loop through the 26 length char array and as soon as you encounter an index that isn’t 0 then the strings aren’t anagrams.
O(1) because 26 char array doesn’t grow with size.
For unicode follow-up, you can use a hash table.