All Patterns
Pattern 14
Trie
A tree where each node represents a character. Enables O(m) prefix searches (m = word length) instead of O(n·m) linear scan through all words.
Time
O(m) per operation
Space
O(n · m)
Recognize it when
- Autocomplete / prefix search
- Word dictionary with wildcard search
- Word search II (multiple words in grid)
- Longest common prefix
Progress0/5
0 solved0 attempted
Questions — ordered by difficulty
#208Medium
Implement Trie (Prefix Tree)
Implement a trie with insert, search (exact), and startsWith (prefix) operations.
triedesignstring
#211Medium
Design Add and Search Words Data Structure
Design a data structure that supports adding words and searching with '.' as wildcard.
triedesigndfs
#648Medium
Replace Words
Replace words in a sentence with their shortest root from a dictionary.
triestringhash-map
#336Hard
Palindrome Pairs
Find all pairs of indices (i, j) such that words[i] + words[j] is a palindrome.
triestringpalindrome
#212Hard
Word Search II
Find all words from a dictionary that exist in a 2D board where letters must be adjacent (no reuse).
backtrackingtriedfs