Group Anagrams
Group strings that are anagrams of one another.
Why does this pattern fit?
Restate the exact job
Group strings that are anagrams of one another.
Anagrams share a canonical character-count signature.
O(total characters) time with fixed alphabet · O(total characters) space
A delimiter-free signature can collide; sorting every word costs more.
How to solve Group Anagrams
The goal is to solve this problem from the pattern, not to memorize a finished answer. Use this as a check after your own attempt.
What the question asks
Group strings that are anagrams of one another.
Why Array scans & hashing fits
Anagrams share a canonical character-count signature.
State to maintain
A map from signature to its group of strings.
Transition
Build each word’s signature and append it to the matching bucket.
Time and space
O(total characters) time with fixed alphabet · O(total characters) space
Counterexample to the tempting mistake
A delimiter-free signature can collide; sorting every word costs more.
Prove it again tomorrow
Close this page. Rebuild the state and transition from memory, write a test that exposes the mistake above, then solve a fresh input without looking back. A same-day reread is practice, not proof of retention.