complexityhashingstrings
anagrams need counts, not sorted copies
Anonymous
For lowercase a-z input, a 26-slot count array checks an anagram in O(k) time and O(1) extra space. Sorting each string takes O(k log n) only when the string length is n; more generally, sorting length-k strings takes O(k log k). For unrestricted characters, use a map or sort; the fixed array only fits a known alphabet.
0