Trie Practice Questions
Eight problems that cover every trie shape: the plain set, the value-carrying map, the wildcard walk, the trie-guided grid DFS, and the bitwise trie. Once you’ve done these, “set of strings sharing prefixes” becomes a reflex.
The trie recognition signals:
- A set/dictionary of strings is queried for membership or prefixes repeatedly.
- You’re matching characters one at a time against many candidate words at once.
- The problem says “prefix,” “starts with,” “shortest root,” “autocomplete,” or “common prefix.”
- XOR maximization/pairs over integers → the bitwise trie.
If you see one of these, build a trie before you write anything else.
Easy
| Problem | Pattern | Status |
|---|---|---|
| Implement Trie (Prefix Tree) | the core insert/search/startsWith | Available |
Medium
| Problem | Pattern | Status |
|---|---|---|
| Add & Search Word (wildcards) | DFS walk with . matching any child | Available |
| Replace Words | walk to the shortest end-of-word root | Available |
| Map Sum Pairs | store values at nodes, sum a subtree/prefix | Available |
| Longest Word in Dictionary | word buildable one char at a time | Available |
| Search Suggestions System | autocomplete — top-k per prefix | Available |
| Maximum XOR of Two Numbers | bitwise trie, greedy MSB-first | Available |
Hard
| Problem | Pattern | Status |
|---|---|---|
| Word Search II | trie + grid DFS with branch pruning | Available |
More Practice (Coming Soon)
| Problem | Pattern | Status |
|---|---|---|
| Concatenated Words | trie + DP word-break | Coming Soon |
| Stream of Characters | suffix trie, query reversed | Coming Soon |
| Palindrome Pairs | trie of reversed words | Coming Soon |
| Word Squares | prefix-indexed backtracking | Coming Soon |
| Design Search Autocomplete System | trie + ranking + live input | Coming Soon |
| Maximum XOR With an Element From Array | offline queries + bitwise trie | Coming Soon |
| Count Pairs With XOR in a Range | bitwise trie counting | Coming Soon |
| Short Encoding of Words | trie of reversed words | Coming Soon |