week 7 of 15
Tree BFS, construction and tries
Get comfortable with these coding mechanics first: a queue loop that processes one level at a time, building a tree with recursion and index ranges, a class with a map of children. Template to type from memory by the end of the week: level-order: while the queue is not empty, size = len(queue), process exactly size nodes.
- 58Binary Tree Level Order Traversal (opens LeetCode in a new tab)BFS with a queueMedium
- Common mistake
- Reading len(queue) after pushing children.
- 59Binary Tree Right Side View (opens LeetCode in a new tab)Level order, keep the lastMedium
- Common mistake
- Taking the first node instead of the last.
- 60Implement Trie (Prefix Tree) (opens LeetCode in a new tab)Trie node classMedium
- Common mistake
- search needs is_end at the end. startsWith does not.
- 61Design Add and Search Words Data Structure (opens LeetCode in a new tab)Trie + DFS on wildcardsMedium
- Common mistake
- Passing the word index and the node together.
- 62Lowest Common Ancestor of a Binary Tree (opens LeetCode in a new tab)DFS returns a found nodeMedium
- Common mistake
- Not defining in words what dfs returns.
- 63Construct Binary Tree from Preorder and Inorder Traversal (opens LeetCode in a new tab)Divide and conquer with an index mapMedium
- Common mistake
- Building right before left. Preorder order matters.
- 64Binary Tree Maximum Path Sum (opens LeetCode in a new tab)Return a gain, track a global bestHard
- Common mistake
- Same trap as Diameter: return value differs from the tracked answer.
- 65Serialize and Deserialize Binary Tree (opens LeetCode in a new tab)Preorder with null markersHard
- Common mistake
- Using inconsistent delimiters, or reading tokens back in a different order than you wrote them.