FastPrepMinimum-Sum Root-to-Leaf Path
Problems/Minimum-Sum Root-to-Leaf Path

Minimum-Sum Root-to-Leaf Path

Meta logoMeta● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Meta onsite interview. The original report gives a binary tree, asks for the root-to-leaf path with the smallest sum, and mentions depth-first search. It does not say how to write the tree, how to break ties, or the limits on the numbers. Here, the tree comes in level order, ties go to the left child first, and values can be negative within limits.

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]
root
1245367

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]
root
511

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]
root
10-5-102

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.

More Meta Onsite Interview questions

  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Linear Layer Forward and Backward PassesONSITE INTERVIEW · Seen Sep 2026
  • Reservoir Sampling with Recorded DrawsONSITE INTERVIEW · Seen Sep 2026
  • Stochastic Gradient Descent with MomentumONSITE INTERVIEW · Seen Sep 2026
  • Top K Largest Values with a HeapONSITE INTERVIEW · Seen Sep 2026
  • Partition a Card Deck into FifteensONSITE INTERVIEW · Seen Sep 2026
  • Insert into a Sorted Circular ListONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Diagonal Traversal of a Binary TreeAmazon · ONSITE INTERVIEW
  • Render an Org Chart and Find Skip-Level PairsSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Find Leaves of a Binary TreeLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Delete Nodes and Return Forest RootsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Render a Task Tree from CSV RowsStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Filter Undesired Comments and Their DescendantsReddit · PHONE SCREEN · ONSITE INTERVIEWReddit interview questions
  • JSON Path Lookup with Implicit Array WildcardsMongoDB · ONSITE INTERVIEWMongoDB interview questions
  • Delete and Compact a Forest SubtreePinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
  • Onion-Peel Layers of a Binary TreeeBay · ONSITE INTERVIEWeBay interview questions

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer Phone Screen: 1 Experience
  • Meta Software Engineer Onsite Questions: 3 Experiences
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public int[] minimumSumRootToLeafPath(TreeNode root) {
        // Write your code here.
    }
}
Checking account…