Strings & Tries
Trie
When you see it
Signal words
If the prompt uses any of these, this pattern should come to mind first.
prefixautocompletedictionaryword searchstartsWithwildcard
Practice
Drill this pattern with an AI trainer — reply only with Hint, Next, Lost, or paste your code.
Ask yourself
- Are many words queried by prefix?
- Is
startsWithor dictionary pruning repeated? - Would a tree of characters avoid repeated string scans?
Classic problem
Implement Trie (LeetCode 208) — Insert words letter by letter; shared prefixes reuse existing nodes. Words end at marked isWord nodes.
Input: insert "car", "cat", "dog"
Output: search("car") = true, search("ca") = false, startsWith("ca") = true — the trie stores all three words, sharing the c→a path for “car” and “cat”.
Common pitfalls
Forgetting the terminal marker for words that are also prefixes.
Creating substrings repeatedly instead of moving by index.