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
1 pattern

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)

Easy problems
No.Problem
0014Longest Common Prefix
2932Maximum Strong Pair XOR I
1065Index Pairs of a StringPremium

Medium (24)

Medium problems
No.Problem
0139Word Break
0208Implement Trie (Prefix Tree)
0211Design Add and Search Words Data Structure
0386Lexicographical Numbers
0421Maximum XOR of Two Numbers in an Array
0648Replace Words
0676Implement Magic Dictionary
0677Map Sum Pairs
0692Top K Frequent Words
0720Longest Word in Dictionary
0792Number of Matching Subsequences
0820Short Encoding of Words
1023Camelcase Matching
1233Remove Sub-Folders from the Filesystem
1268Search Suggestions System
2261K Divisible Elements Subarrays
2452Words Within Two Edits of Dictionary
2707Extra Characters in a String
0616Add Bold Tag in StringPremium
0758Bold Words in StringPremium
1166Design File SystemPremium
1698Number of Distinct Substrings in a StringPremium
1804Implement Trie II (Prefix Tree)Premium
1858Longest Word With All PrefixesPremium

Hard (22)

Hard problems
No.Problem
0140Word Break II
0212Word Search II
0336Palindrome Pairs
0440K-th Smallest in Lexicographical Order
0472Concatenated Words
0745Prefix and Suffix Search
1032Stream of Characters
1178Number of Valid Words for Each Puzzle
1316Distinct Echo Substrings
1707Maximum XOR With an Element From Array
1803Count Pairs With XOR in a Range
1948Delete Duplicate Folders in System
2227Encrypt and Decrypt Strings
2416Sum of Prefix Scores of Strings
2935Maximum Strong Pair XOR II
2977Minimum Cost to Convert String II
0425Word SquaresPremium
0527Word AbbreviationPremium
0588Design In-Memory File SystemPremium
0642Design Search Autocomplete SystemPremium
1938Maximum Genetic Difference Query
2479Maximum XOR of Two Non-Overlapping SubtreesPremium