mediumTriesFacebookAmazon
Wildcard Word Vault
A password-recovery drawer stores admitted words; later queries probe entries using '.' as a universal joker slot.
Design a data structure supporting addWord(word) and search(word) where '.' matches any single character.
Choose approach
·
b
a
d
1/7
Narrationstep 1 of 7
addWord("bad") inserts along 3 edges.
Variables
word=bad
nodes=4
How to think about it
- No wildcards -> plain trie walk, O(L).
- '.' triggers a branching DFS over all children at that level.
- Return true the moment any branch terminates on an `isEnd` node.
Edge cases to catch in interview
- All '.' pattern -> depth-first scan limited to pattern length.
- Pattern longer than any stored word -> early termination.
Examples
Example 1
[true]{"ops":[{"op":"addWord","word":"a"},{"op":"search","pattern":"."}]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed