knaxuslearn · build · ship

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.

  1. 58Binary Tree Level Order Traversal (opens LeetCode in a new tab)BFS with a queueMediumcore
    Common mistake
    Reading len(queue) after pushing children.
  2. 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.
  3. 60Implement Trie (Prefix Tree) (opens LeetCode in a new tab)Trie node classMediumcore
    Common mistake
    search needs is_end at the end. startsWith does not.
  4. 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.
  5. 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.
  6. 63Construct Binary Tree from Preorder and Inorder Traversal (opens LeetCode in a new tab)Divide and conquer with an index mapMediumcore
    Common mistake
    Building right before left. Preorder order matters.
  7. 64Binary Tree Maximum Path Sum (opens LeetCode in a new tab)Return a gain, track a global bestHardcore
    Common mistake
    Same trap as Diameter: return value differs from the tracked answer.
  8. 65Serialize and Deserialize Binary Tree (opens LeetCode in a new tab)Preorder with null markersHardcore
    Common mistake
    Using inconsistent delimiters, or reading tokens back in a different order than you wrote them.