Tries
Prefix trees for fast autocomplete, dictionary lookup, and word search.
Tries Practice Problems
Easy
4 problems- 460easy
Implement Trie (Prefix Tree)
Build a tree of letters that can store words and answer both "is this an exact word?" and "does any word start like this?".
- 461easy
Longest Common Prefix
Find the longest beginning that every word shares by walking down a trie until the path splits or a word ends.
- 462easy
Index Pairs of a String
Report the start and end position of every place a dictionary word appears inside a string, using a trie to stop dead ends early.
- 463easy
Longest Word in Dictionary
Find the longest word that can be built one letter at a time, where every step along the way is also a word in the list.
Medium
4 problems- 464medium
Replace Words
Swap each word in a sentence for the shortest dictionary root that starts it, found by walking the word down a trie of roots.
- 465medium
Design Add and Search Words Data Structure
Store words in a trie and support searches where a dot stands for any single letter, by trying every branch at a dot.
- 466medium
Map Sum Pairs
Keep a running total on every trie node so the sum of all values whose key starts with a prefix is a single lookup.
- 467medium
Search Suggestions System
Show up to three matching products after each letter typed, by caching the best three answers on every trie node.
Hard
2 problems- 468hard
Stream of Characters
Answer after every arriving letter whether the stream now ends with one of the stored words, using a trie of reversed words.
- 469hard
Concatenated Words
Find every word that is made by gluing together two or more shorter words from the same list, using a trie to try each split point.
Related concepts
| Topic | Description |
|---|---|
| Arrays | Ordered indexable collection for O(1) access by position. |
| Linked Lists | Nodes linked by pointers — insert and delete without shifting a contiguous block. |
| Stacks | Last-in, first-out collection for undo, parsing, and nested work. |
| Queues | First-in, first-out collection for scheduling, BFS, and buffering. |
| Hash Tables | Key-to-value lookup in average O(1) via hashing into buckets. |
| Trees | Hierarchical nodes with parent–child links for ordered and nested data. |