Trie
11 problems · 9 with full explanations
2 Easy4 Medium3 Hard
A trie (prefix tree) stores strings character by character, enabling O(L) insert, search, and prefix queries where L is string length. Use it for autocomplete, word search in a grid, longest common prefix, and IP routing. Each node has up to 26 children (for lowercase letters).
How to practice
To practice Trie problems effectively, start with the Easy problems listed below, trace through each solution on paper, then re-implement without looking. When you can recognise the trie pattern within 30 seconds of reading a new problem, move on to Medium difficulty. Use the related topic pages and our study guide for a structured progression.
Start here (Easy + explained)
All Trie problems
- 212.Word Search IIHard
- 386.Lexicographical NumbersMedium
- 440.K-th Smallest in Lexicographical OrderHard
- 820.Short Encoding of WordsMedium
- 1233.Remove Sub-Folders from the FilesystemMedium
- 1938.Maximum Genetic Difference QueryUnknown
- 1948.Delete Duplicate Folders in SystemUnknown
- 2416.Sum of Prefix Scores of StringsHard
- 2707.Extra Characters in a StringMedium
- 3042.Count Prefix and Suffix Pairs IEasy
- 3043.Find the Length of the Longest Common PrefixEasy