Node 5 has children 7 and 8. Its parent 4 has another child 6.
The best path through 5 totals 20. May 4 attach that whole path to itself and 6?
1 / 12
Maximum Depth of Binary Tree — predict before coding
Depth counts nodes on a longest root-to-leaf path. The empty-tree base case zero makes a leaf's depth emerge naturally as one.
Decision: What are the depths of an empty tree, a leaf, and a four-node chain?
2 / 12
Same Tree — predict before coding
Value sequences alone omit shape. Equality must pair corresponding child positions, including nil positions.
Decision: Are a root 1 with left child 2 and a root 1 with right child 2 the same tree?
3 / 12
Invert Binary Tree — predict before coding
Inversion is a structural permutation of existing child pointers, not a sort of values. The root node itself remains the same object.
Decision: After inverting a root with only a left child, where is that same child node?
4 / 12
Symmetric Tree — predict before coding
Mirror comparison pairs the outside children and the inside children. Comparing left with left tests equality, not symmetry.
Decision: Can equal values on the left and right roots prove symmetry when one has a left child and the other also has a left child?
5 / 12
Construct Binary Tree from Preorder and Inorder Traversal — predict before coding
Preorder chooses the next root; inorder tells which values belong to each child subtree. Unique values make the split unambiguous.
Decision: For preorder [2,1,3] and inorder [1,2,3], which value is root and which inorder ranges belong to its children?
6 / 12
Construct Binary Tree from Inorder and Postorder Traversal — predict before coding
Reading postorder through one backward cursor gives root, right, left, so that implementation builds right first. The reference instead gives each child its own ranges and safely builds left first.
Decision: For inorder [1,2,3] and postorder [1,3,2], which child subtree must be built first while consuming postorder backward?
7 / 12
Path Sum — predict before coding
A root-to-leaf condition is stricter than reaching a target at any node. A zero remaining sum is meaningful only when the current node is a leaf.
Decision: For root 5 with a single child 1, is target 5 a successful root-to-leaf sum?
8 / 12
Sum Root to Leaf Numbers — predict before coding
The recursive state is the numeric value of the entire root-to-parent digit prefix. Extending by one digit is multiplication by ten plus that digit.
Decision: For root 1 with leaf children 2 and 3, why is the answer 25 rather than 6?
9 / 12
Binary Tree Maximum Path Sum — predict before coding
A path may join two downward branches at one highest node, but a branch returned to a parent may use only one child. Mixing these two quantities creates a branching object rather than a path.
Decision: At a node valued 10 with child gains 4 and 7, what complete-path candidate is recorded and what gain can be returned to its parent?
10 / 12
Lowest Common Ancestor of a Binary Tree — predict before coding
The return value summarizes whether the subtree contains a target or already contains their common ancestor. Target identity is a pointer relation, not a value comparison.
Decision: If p is an ancestor of q, should the answer be p or p’s parent?
11 / 12
Change the return contract
The LCA helper assumes both target pointers are present. A new API must return nil if either is missing.
Construct a failing input for the old helper, then specify enough returned information to repair the promise.
12 / 12
←/→ or click edges to navigate · ? help · N notes · F fullscreen