Trie
A trie (prefix tree) stores strings by shared prefixes, so a prefix lookup or autocompletion costs only the length of the query, not the size of the dictionary. Reach for it on word-search, prefix-matching, and dictionary problems.
4 LeetCode problems solved with the Trie pattern. Practice them with spaced repetition so the pattern sticks.
- Design Add and Search Words Data StructureMEDIUM · O(n) per addWord, O(26^d * n) per search with d dots
- Implement Trie (Prefix Tree)MEDIUM · O(L)
- Search Suggestions SystemMEDIUM · O(n*m + m^2)
- Word Search IIHARD · O(m*n*4*3^(L-1))
See the full solution
The complete approach, reference solutions in 5 languages, and a step-by-step visualization — then add this problem to your spaced-repetition schedule.
Start free →