FastPrepSum Root-to-Leaf Numbers
Problems/Sum Root-to-Leaf Numbers

Sum Root-to-Leaf Numbers

Meta logoMeta● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Meta onsite interview. Our version is about 99% the same as the reported question.

You are given the root of a binary tree. Every node stores one decimal digit from 0 through 9. Each root-to-leaf path represents the number formed by reading its digits from root to leaf.

Return the sum of the numbers represented by all root-to-leaf paths. A leaf has no children. Return 0 for an empty tree.

Follow-up

How can an iterative traversal avoid call-stack overflow on a very deep tree?

Function

sumNumbers(root: TreeNode) → int

Examples

Example 1

root = [1,2,3]return = 25
root
123

The paths form 12 and 13, whose sum is 25.

Example 2

root = [4,9,0,5,1]return = 1026
root
49510

The paths form 495, 491, and 40.

Example 3

root = []return = 0
root
empty

An empty tree has no root-to-leaf paths.

Constraints

  • Each node value is between 0 and 9.
  • The tree may be empty.
  • The final sum fits in a signed 32-bit integer.

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

  • Maximum Root-to-Leaf and Leaf-to-Leaf Path SumsAmazon · ONSITE INTERVIEW
  • Binary Tree Level Order TraversalGoogle · ONSITE INTERVIEW
  • Lowest Common Ancestor Only When Both Targets ExistAdobe · ONSITE INTERVIEW
  • Validate Binary Search TreeGoldman Sachs · ONSITE INTERVIEW
  • Balanced Tree Node ReportNetflix · ONSITE INTERVIEW
  • Trim a Binary Search TreeBloomberg LP · ONSITE INTERVIEW
  • Height-Balanced Binary TreeExpedia · ONSITE INTERVIEW
  • Binary Tree Target-Sum PathsByteDance · PHONE SCREEN
  • Validate Binary Search TreeLyft · PHONE SCREEN
  • Lowest Common Ancestor in a Binary TreeZillow · PHONE SCREEN
See 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 sumNumbers(TreeNode root) {
        // Write your code here.
    }
}
Checking account…