Problem context and objectives
Mission briefing
Puzzle systems engineer · A game mechanic is behaving incorrectly
File words by a canonical signature: The Anagram Archive.
Brute force may pass the demo but fail when the world fills with players.
How you win
- 1Recognize when Canonical-key hashing matches the clues
- 2Keep this true after every move: every word in one bucket has exactly the same character multiset
- 3Reach the result within O(n k log k)
Rules and pressure
- Target cost: O(n k log k)
- State rule: every word in one bucket has exactly the same character multiset
Lesson 1 of 3
Live algorithm trace
Canonical-key hashing
Complete execution1 of 7
Create an insertion-ordered map for canonical signatures.
1
groups = ordered map2
for word in words3
key = sorted characters4
append word to groups[key]5
return groups in key discovery ordergroups = {}
Truth to preserve / Cost target
Truth to preserve
every word in one bucket has exactly the same character multiset
Cost target
O(n k log k)
Anagrams become identical after the same canonical transformation. Use a sorted-character signature as a hash key, append each word to its matching group, then return groups in first-signature order.
Your call · What should guide every step of this algorithm?