hash_table.state
Input
Hash table
Current look-up
Match / window
Stored entry
What is Group Anagrams
Anagrams share a letter multiset. Sort the letters of a word (or pack a 26-count tuple) and use that string as a hash-map key. Every word with the same key falls into the same bucket.
eat tea tan ate nat bat. Watch buckets aet, ant, and abt fill.Interactive trace
Pseudocode & Complexity
| Operation | Time |
|---|---|
| Key of one word | O(L log L) |
| All words | O(n L log L) |
| Space | O(n L) |
Python implementation