AlgoPrecision

Hashing Visualizer

Hash Tables

Watch keys map into buckets with modulo hashing, collisions, chain traversal, and live average versus worst-case complexity.

O(n * k log k)
map: sorted letters -> wordsactive key: 18
Bucket 0
empty
Bucket 1
empty
Bucket 2
empty
Bucket 3
empty
Bucket 4
empty
Bucket 5
empty
Bucket 6
empty

Time

O(n)

Space

O(n)

Step Note

Group words by their sorted-letter signature.

Details
function groupAnagrams(words: string[]) {
  const groups = new Map<string, string[]>()
  for (const word of words) {
    const key = [...word].sort().join('')
    groups.set(key, [...(groups.get(key) ?? []), word])
  }
  return [...groups.values()]
}