Implement Trie | One Walk, Three Operations | LeetCode 75 #70
Placements
0:00 / 0:00
Implement Trie | One Walk, Three Operations | LeetCode 75 #70
1 просмотр · 7 дней назад
Placements
2 подписчика
1 просмотр · 7 дней назад
Implement Trie (Prefix Tree) — LeetCode 208 | One Walk, Three Operations
The trie onboarding video: build the node-structure intuition (children array + isEnd flag) and watch insert, search and startsWith as ONE walk down the tree with three different endings.
What you will learn:
Why a trie: hashset gives fast search but NO prefix queries; sorted list gives prefix range but costs O(L log n) plus O(n) inserts
The TrieNode: children[26] indexed by c - 'a', and the 208-bytes-per-node memory tradeoff vs map
The isEnd flag: why search("app") is FALSE when only "apple" was inserted — the classic interview trap
insert / search / startsWith as the same walk, different endings
Complexity: O(L) time per operation, O(total characters) space
C++ code explained line by line, debugger-style, each line lighting up as it mutates the live tree.
Chapters:
0:00:00 Hook: one walk, three endings
0:01:29 The problem (LC 208)
0:03:14 HARD 1: why a trie, not a hashset
0:04:57 HARD 1: prefix is a location
0:06:35 HARD 2: children[26] and the memory fee
0:09:33 HARD 3: the isEnd flag trap
0:12:14 Dry run: insert apple
0:13:52 Dry run: search + startsWith
0:15:41 Dry run: insert app, ape (sharing)
0:17:14 Dry run: startsWith walk
0:18:53 Dry run 2: bat, ball, bad
0:20:33 Code: struct TrieNode
0:22:32 Code: insert (live encore)
0:24:44 Code: search
0:26:21 Code: startsWith
0:28:05 Proof: O(L) time
0:30:41 Edge cases
0:32:36 Recap + next video
LeetCode 75 series — video 70. Full C++ solution in the pinned comment.