Strings that are anagrams share the same canonical key.
For each string, build a key (either sorted characters or a 26-count signature). Use a hash map from key to list of strings.
All anagrams map to the same key, so grouping by key collects exactly the strings that are permutations of each other.
Strings that are anagrams share the same canonical key.
For each string, build a key (either sorted characters or a 26-count signature). Use a hash map from key to list of strings.
All anagrams map to the same key, so grouping by key collects exactly the strings that are permutations of each other.