The Insufficient Nodes in Root to Leaf Paths interview question asks you to prune a binary tree. A node is considered "insufficient" if every path from the root through that node to any leaf has a total sum strictly less than a given limit. You need to remove all such nodes from the tree and return the root of the pruned tree.
Amazon and other tech firms use this Insufficient Nodes coding problem to test a candidate's ability to propagate information up and down a tree. It requires a "post-order" logic because you can't decide to delete a node until you've evaluated all the leaf paths going through it. It’s an advanced Binary Tree interview pattern that evaluates recursion and path-sum logic.
This problem is solved using Post-order Depth-First Search (DFS).
currentSum from the root.currentSum + leaf.val < limit. If it is, the leaf is insufficient.null if it should be deleted.Tree: 1 is root, children 2 and 3. Limit = 5.
null.
If child 3 was actually 5, then Path 2 (Sum 6) would be sufficient. Node 3 and Root 1 would stay, but Node 2 would be pruned.currentSum is already low, without checking if a leaf far below could bring the total above the limit.Practice problems that require Bottom-Up deletion. The key is to make the recursive function return either the node or null. The parent then updates its child pointer: node.left = solve(node.left, ...)—this ensures the tree is modified correctly during the return phase.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Equal Tree Partition | Medium | Solve | |
| Maximum Average Subtree | Medium | Solve | |
| Binary Tree Coloring Game | Medium | Solve | |
| Maximum Product of Splitted Binary Tree | Medium | Solve | |
| Delete Leaves With a Given Value | Medium | Solve |