← Hash Map

Pattern Recognition Drill

#25 — Group anagrams

Medium Hash Maps

The Problem

Group a list of words by anagram.

What approach would you use?

Think about it before scrolling down.

Key Signals

Hash Map

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).

← #24 #26 →