← Trie

Pattern Recognition Drill

#108 — Design Add and Search Words

Medium Tries

The Problem

Design a data structure that supports adding words and searching with '.' wildcards that match any character.

What approach would you use?

Think about it before scrolling down.

Key Signals

Trie

Insert normally. On search, DFS when encountering '.', trying all children. O(26^dots * L) worst case.

Alt: Hash Map

Group words by length, brute-force match on '.' — slower for large dictionaries.

Common Trap

The '.' wildcard means you must try ALL children at that level — can't just follow one path.

← #107