Pattern Recognition Drill
Medium Hash Maps
The Problem
Group a list of words by anagram.
What approach would you use?
Think about it before scrolling down.
Key = sorted(word), value = list of words. All anagrams map to the same key. O(n * k log k).
Common Trap
Comparing all pairs is O(n² * k). Using a character count tuple as key avoids sorting: O(n * k).