Trie LeetCode Problems: All 49,
With Python Solutions
Every problem in this library that LeetCode tags Trie. 36 of them carry a complete Python solution, a worked example and the time and space complexity of the approach.
- Easy
- 3
- Medium
- 24
- Hard
- 22
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.
Eyes only
When the Trie problem arrives live.
In the live round, Stealth Interview reads the 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 says. It's a desktop app for macOS and Windows, invisible to screen sharing.
Trie problems by difficulty
Problems with a complete Python solution are listed first, then by ascending problem number.
Easy (3)
| No. | Problem | Topics |
|---|---|---|
| 0014 | Longest Common Prefix | |
| 2932 | Maximum Strong Pair XOR I | |
| 1065 | Index Pairs of a StringPremium |
Medium (24)
| No. | Problem | Topics |
|---|---|---|
| 0139 | Word Break | |
| 0208 | Implement Trie (Prefix Tree) | |
| 0211 | Design Add and Search Words Data Structure | |
| 0386 | Lexicographical Numbers | |
| 0421 | Maximum XOR of Two Numbers in an Array | |
| 0648 | Replace Words | |
| 0676 | Implement Magic Dictionary | |
| 0677 | Map Sum Pairs | |
| 0692 | Top K Frequent Words | |
| 0720 | Longest Word in Dictionary | |
| 0792 | Number of Matching Subsequences | |
| 0820 | Short Encoding of Words | |
| 1023 | Camelcase Matching | |
| 1233 | Remove Sub-Folders from the Filesystem | |
| 1268 | Search Suggestions System | |
| 2261 | K Divisible Elements Subarrays | |
| 2452 | Words Within Two Edits of Dictionary | |
| 2707 | Extra Characters in a String | |
| 0616 | Add Bold Tag in StringPremium | |
| 0758 | Bold Words in StringPremium | |
| 1166 | Design File SystemPremium | |
| 1698 | Number of Distinct Substrings in a StringPremium | |
| 1804 | Implement Trie II (Prefix Tree)Premium | |
| 1858 | Longest Word With All PrefixesPremium |
Hard (22)
| No. | Problem | Topics |
|---|---|---|
| 0140 | Word Break II | |
| 0212 | Word Search II | |
| 0336 | Palindrome Pairs | |
| 0440 | K-th Smallest in Lexicographical Order | |
| 0472 | Concatenated Words | |
| 0745 | Prefix and Suffix Search | |
| 1032 | Stream of Characters | |
| 1178 | Number of Valid Words for Each Puzzle | |
| 1316 | Distinct Echo Substrings | |
| 1707 | Maximum XOR With an Element From Array | |
| 1803 | Count Pairs With XOR in a Range | |
| 1948 | Delete Duplicate Folders in System | |
| 2227 | Encrypt and Decrypt Strings | |
| 2416 | Sum of Prefix Scores of Strings | |
| 2935 | Maximum Strong Pair XOR II | |
| 2977 | Minimum Cost to Convert String II | |
| 0425 | Word SquaresPremium | |
| 0527 | Word AbbreviationPremium | |
| 0588 | Design In-Memory File SystemPremium | |
| 0642 | Design Search Autocomplete SystemPremium | |
| 1938 | Maximum Genetic Difference Query | |
| 2479 | Maximum XOR of Two Non-Overlapping SubtreesPremium |
Keep exploring
Other topics
- 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