Minimum-Sum Root-to-Leaf Path
Reported by candidates from Meta's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Meta reported this one in August 2026, and it looks like a path problem but it's just a tree walk with a running sum. Find the root-to-leaf path with the smallest total, return the values, and break ties by taking the left path first. Signed values mean you can't prune early or assume shorter is smaller. If you've got an OA coming up, this is a clean depth-first traversal with one careful comparison. StealthCoder sits invisibly on your screen as a safety net if you blank on the tie-break or the iterative rewrite mid-assessment.
The problem
Given the root of a nonempty binary tree whose nodes contain signed integers, return the values along a root-to-leaf path whose node-value sum is minimum. A leaf has no left or right child. If several root-to-leaf paths have the same minimum sum, return the first one encountered by a depth-first traversal that explores each node's left child before its right child. Return the selected path as an integer array ordered from the root to the leaf. Function minimumSumRootToLeafPath(root: TreeNode) → int[] Examples Example 1 root = [1,2,3,4,5,6,7] return = [1,2,4] The four root-to-leaf sums are 7, 8, 10, and 11. The minimum is 1 + 2 + 4 = 7. Example 2 root = [5,1,1] return = [5,1] Both leaves produce a sum of 6. The left leaf is visited first, so the left path is returned. Example 3 root = [10,-5,2,null,-10] return = [10,-5,-10] The left path has sum -5, while the right path has sum 12. Negative values therefore make the deeper left path optimal. Constraints The tree contains between 1 and 100000 nodes. -1000000000 <= node.val <= 1000000000. Every root-to-leaf sum fits in a signed 64-bit integer. The input is a valid finite binary tree encoded in level order with explicit null children.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The problem reduces to a DFS that carries a running sum from the root. At each leaf, compare the sum to the best seen so far. Use a strict less-than so the first leaf found, which is the leftmost one, wins ties. That one operator handles the tie rule from Example 2. Negatives are the trap: a partial sum can go down later, so you can't cut a branch because it's currently larger. With up to 100000 nodes, a skewed tree will overflow recursion in many languages, so write it iteratively with an explicit stack, pushing right before left. Store parent pointers or a path stack so you rebuild only the winning path. Use 64-bit sums. If the clock or nerves get you mid-OA, StealthCoder is the hedge that hands you the iterative version in real time.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Minimum-Sum Root-to-Leaf Path cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Meta's OA.
Meta reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum-Sum Root-to-Leaf Path FAQ
What's the trick in the Meta minimum-sum root-to-leaf path problem?+
It's a plain DFS with a running sum, checked only at leaves. The real work is the tie-break and negatives. Update the best only on a strictly smaller sum, and visit left before right. That gives you the first-encountered path without extra logic.
Why can't I prune branches when the sum gets large?+
Node values can be negative, up to -1000000000. A branch with a big partial sum can still drop below the best once it hits deeper negative nodes. Example 3 shows this, where the deeper left path wins. You have to reach every leaf.
How do I handle ties correctly?+
Use strict less-than when comparing a leaf sum to the current best. Traverse left child before right child. The first leaf with the minimum sum gets recorded, and later equal sums don't replace it. Example 2 with [5,1,1] returns the left path [5,1].
Should I write this recursively or iteratively?+
With up to 100000 nodes, a skewed tree can blow the call stack in some languages. Iterative DFS with an explicit stack is safer. Push the right child first so left pops first. Track the sum and path per stack entry or via parent pointers.
How do I prepare for this in 48 hours?+
Practice tree DFS with a carried accumulator, then add path reconstruction. Write it once recursively and once iteratively. Test a single node, an all-negative tree, and a tie case. Use 64-bit ints for sums. That covers what this problem actually tests.