Trie LeetCode Problems: All 49, With Python Solutions
Every problem in this library that LeetCode tags Trie — 49 in total, 36 of them with a complete Python solution, a worked example and the time and space complexity of the approach.
- 49 problems
- 3 Easy
- 24 Medium
- 22 Hard
How Trie problems are solved
A tag names the subject, not the method. These pattern hubs cover the techniques that actually solve Trie problems — each one explains the approach, gives a Python template and states its complexity.
- Trie — Store a set of words by their shared prefixes so lookups cost the length of the word.
Trie problems by difficulty
Problems with a complete Python solution are listed first, then by ascending problem number.
Easy (3)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 14 | Longest Common Prefix | Easy | Trie, Array, String |
| 2932 | Maximum Strong Pair XOR I | Easy | Bit Manipulation, Trie, Array +2 |
| 1065 | Index Pairs of a StringPremium | Easy | Trie, Array, String +1 |
Medium (24)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 139 | Word Break | Medium | Trie, Memoization, Array +3 |
| 208 | Implement Trie (Prefix Tree) | Medium | Design, Trie, Hash Table +1 |
| 211 | Design Add and Search Words Data Structure | Medium | Depth-First Search, Design, Trie +1 |
| 386 | Lexicographical Numbers | Medium | Depth-First Search, Trie |
| 421 | Maximum XOR of Two Numbers in an Array | Medium | Bit Manipulation, Trie, Array +1 |
| 648 | Replace Words | Medium | Trie, Array, Hash Table +1 |
| 676 | Implement Magic Dictionary | Medium | Depth-First Search, Design, Trie +2 |
| 677 | Map Sum Pairs | Medium | Design, Trie, Hash Table +1 |
| 692 | Top K Frequent Words | Medium | Trie, Array, Hash Table +5 |
| 720 | Longest Word in Dictionary | Medium | Trie, Array, Hash Table +2 |
| 792 | Number of Matching Subsequences | Medium | Trie, Array, Hash Table +4 |
| 820 | Short Encoding of Words | Medium | Trie, Array, Hash Table +1 |
| 1023 | Camelcase Matching | Medium | Trie, Array, Two Pointers +2 |
| 1233 | Remove Sub-Folders from the Filesystem | Medium | Depth-First Search, Trie, Array +1 |
| 1268 | Search Suggestions System | Medium | Trie, Array, String +3 |
| 2261 | K Divisible Elements Subarrays | Medium | Trie, Array, Hash Table +3 |
| 2452 | Words Within Two Edits of Dictionary | Medium | Trie, Array, String |
| 2707 | Extra Characters in a String | Medium | Trie, Array, Hash Table +2 |
| 616 | Add Bold Tag in StringPremium | Medium | Trie, Array, Hash Table +2 |
| 758 | Bold Words in StringPremium | Medium | Trie, Array, Hash Table +2 |
| 1166 | Design File SystemPremium | Medium | Design, Trie, Hash Table +1 |
| 1698 | Number of Distinct Substrings in a StringPremium | Medium | Trie, String, Suffix Array +2 |
| 1804 | Implement Trie II (Prefix Tree)Premium | Medium | Design, Trie, Hash Table +1 |
| 1858 | Longest Word With All PrefixesPremium | Medium | Depth-First Search, Trie, Array +1 |
Hard (22)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 140 | Word Break II | Hard | Trie, Memoization, Array +4 |
| 212 | Word Search II | Hard | Trie, Array, String +2 |
| 336 | Palindrome Pairs | Hard | Trie, Array, Hash Table +1 |
| 440 | K-th Smallest in Lexicographical Order | Hard | Trie |
| 472 | Concatenated Words | Hard | Depth-First Search, Trie, Array +3 |
| 745 | Prefix and Suffix Search | Hard | Design, Trie, Array +2 |
| 1032 | Stream of Characters | Hard | Design, Trie, Array +2 |
| 1178 | Number of Valid Words for Each Puzzle | Hard | Bit Manipulation, Trie, Array +2 |
| 1316 | Distinct Echo Substrings | Hard | Trie, String, Hash Function +1 |
| 1707 | Maximum XOR With an Element From Array | Hard | Bit Manipulation, Trie, Array |
| 1803 | Count Pairs With XOR in a Range | Hard | Bit Manipulation, Trie, Array |
| 1948 | Delete Duplicate Folders in System | Hard | Trie, Array, Hash Table +2 |
| 2227 | Encrypt and Decrypt Strings | Hard | Design, Trie, Array +2 |
| 2416 | Sum of Prefix Scores of Strings | Hard | Trie, Array, String +1 |
| 2935 | Maximum Strong Pair XOR II | Hard | Bit Manipulation, Trie, Array +2 |
| 2977 | Minimum Cost to Convert String II | Hard | Graph, Trie, Array +3 |
| 425 | Word SquaresPremium | Hard | Trie, Array, String +1 |
| 527 | Word AbbreviationPremium | Hard | Greedy, Trie, Array +2 |
| 588 | Design In-Memory File SystemPremium | Hard | Design, Trie, Hash Table +2 |
| 642 | Design Search Autocomplete SystemPremium | Hard | Depth-First Search, Design, Trie +4 |
| 1938 | Maximum Genetic Difference Query | Hard | Bit Manipulation, Depth-First Search, Trie +2 |
| 2479 | Maximum XOR of Two Non-Overlapping SubtreesPremium | Hard | Tree, Depth-First Search, Graph +1 |
Keep exploring
- Array1,569
- String672
- Hash Table588
- Math485
- Dynamic Programming481
- Sorting392
- Greedy346
- Depth-First Search289
- Binary Search253
- Database249
- Tree225
- Breadth-First Search223
- Matrix216
- Two Pointers201
- Bit Manipulation194
- Binary Tree174
- Heap (Priority Queue)163
- Prefix Sum157
- Stack157
- Simulation144
- Graph138
- Counting126
- Design122
- Sliding Window116
When the Trie problem arrives live
Stealth Interview is a desktop app for macOS and Windows. It reads the coding problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer is saying — while staying invisible to screen sharing.