Tries

Tries store strings character by character, enabling O(L) operations on prefixes and words.

35 lessons
205 min

Lessons

1. Intro

Why tries matter

2m

2. Trie Node Structure

Children for each character

3m

3. Trie Insert Operation

Character by character

3m

4. Trie Search Operation

Following the path

2m

5. Prefix Search

The trie advantage

2m

6. Problem - Implement Trie

The foundational trie problem

3m1 problems

7. Trie Implementation

Complete solution

4m

8. Implement Trie Solution

Build your trie

15m1 problems

9. Counting Words with Prefix

Augmenting the trie

3m

10. Trie Deletion

Removing words

4m

11. Problem - Add and Search Word

Trie with wildcards

3m1 problems

12. Wildcard Search Strategy

DFS for dot matching

3m

13. Add and Search Solution

Implement your solution

15m1 problems

14. Problem - Word Search II

Trie + backtracking

3m1 problems

15. Word Search II: Trie Approach

Efficient multi-word search

4m

16. Word Search II Optimizations

Pruning and cleanup

3m

17. Word Search II Solution

Implement your solution

25m1 problems

18. Problem - Longest Word in Dictionary

Trie with constraints

3m1 problems

19. Longest Word Solution

BFS on valid paths

12m1 problems

20. Compressed Tries (Radix Trees)

Space optimization

3m

21. Suffix Tries and Suffix Trees

Pattern matching powerhouse

3m

22. Problem - Maximum XOR of Two Numbers

Bitwise trie application

3m1 problems

23. Bitwise Trie Concept

Numbers as bit strings

4m

24. Maximum XOR Solution

Implement your solution

15m1 problems

25. Problem - Search Autocomplete

Top-k suggestions

3m1 problems

26. Autocomplete Design

Trie with rankings

4m

27. Autocomplete Solution

Implement your solution

25m1 problems

28. Problem - Replace Words

Trie for dictionary lookup

3m1 problems

29. Replace Words Solution

Find shortest prefix match

12m1 problems

30. Array vs Map Children

Implementation trade-offs

2m

31. Trie Memory Optimization

Reducing space usage

3m

32. Trie vs Hash Set

When to use which

2m

33. Counting Distinct Substrings

Suffix trie application

3m

34. Quiz: Tries

Test your understanding

5m1 problems

35. Section Recap

What you learned

3m

Practice Problems

1.
Vasiliy's MultisetCodeforcesmedium

Classic 01-trie for maximum XOR queries. Insert, delete, and find max XOR with given number.

2.
Sausage MaximizationCodeforceshard

Prefix XOR with binary trie. Maximize XOR of prefix and suffix using 01-trie queries.

3.

01-trie with counting. Count elements where XOR with x is less than threshold.

4.

Binary search with trie-like state tracking. Understand prefix properties in sequences.

5.
Prefix-Suffix PalindromeCodeforcesmedium

String manipulation with prefix/suffix matching. Trie-like thinking for palindrome construction.

6.
Maximum XOR SecondaryCodeforcesmedium

Monotonic stack with XOR. Combines stack technique with binary representation analysis.

7.
Vampiric PowersCodeforcesmedium

XOR subsequence problem. Use prefix XOR with set to track achievable values.

8.
Nearest CitiesCodeforcesmedium

Coordinate queries with trie-like structure for nearest neighbor in specific direction.

9.
XOR InverseCodeforceshard

Minimize inversions after XOR. Binary trie to count inversions at each bit level.

10.

Segment tree with merge properties. Trie-like divide for range maximum queries.

11.
Good SubstringsCodeforcesmedium

Count distinct substrings with constraints using trie. Classic string trie application.

12.
PasswordCodeforcesmedium

Find string appearing as prefix, suffix, and middle. Z-function or trie approach.

13.

Fundamental trie implementation. Insert, search, and startsWith operations.

14.

Trie with wildcard search using DFS. Handle '.' matching any character.

15.
Word Search IILeetCodehard

Trie + DFS on grid. Find all words from dictionary in board. Prune with trie prefixes.

16.

Binary trie for maximum XOR. Greedy bit-by-bit selection using trie traversal.

17.
Replace WordsLeetCodemedium

Replace words with shortest root in dictionary. Classic trie prefix matching.

18.

Find longest word buildable character by character. Trie with valid word marking.

19.

Autocomplete with trie. Return top 3 lexicographically smallest matches per prefix.

20.
Map Sum PairsLeetCodemedium

Trie storing sums at nodes. Sum values of all keys with given prefix.

Ready to start learning?

Access all 35 lessons with interactive content and progress tracking.