PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Meta

Sum numbers formed by root-to-leaf paths

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to work with binary tree traversal and path-based numerical aggregation, testing competency in tree data structures and algorithmic reasoning within the Coding & Algorithms domain.

  • medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Sum numbers formed by root-to-leaf paths

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given the root of a binary tree where each node contains a single digit from 0 to 9. Each root-to-leaf path represents a number obtained by concatenating the digits along the path from the root down to a leaf. For example, if a path is root → 1 → 2 → 3, it represents the number 123. Write a function that returns the sum of all numbers formed by all root-to-leaf paths in the tree. - Input: the root node of a binary tree. - Output: an integer representing the sum of all root-to-leaf numbers. Constraints: - Each node value is a digit from 0 to 9. - The tree has at most 1000 nodes. Describe your algorithm and its time and space complexity. You do not need to provide actual code.

Quick Answer: This question evaluates a candidate's ability to work with binary tree traversal and path-based numerical aggregation, testing competency in tree data structures and algorithmic reasoning within the Coding & Algorithms domain.

Related Interview Questions

  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve a Key-Door Corridor Maze - Meta (medium)
  • Solve Array Merge and Parentheses Cleanup - Meta (medium)
  • Solve Two Backtracking Array Problems - Meta (hard)
  • Solve Maze and Suffix Problems - Meta (medium)
Meta logo
Meta
Dec 8, 2025, 7:54 PM
Software Engineer
Onsite
Coding & Algorithms
2
0

You are given the root of a binary tree where each node contains a single digit from 0 to 9.

Each root-to-leaf path represents a number obtained by concatenating the digits along the path from the root down to a leaf. For example, if a path is root → 1 → 2 → 3, it represents the number 123.

Write a function that returns the sum of all numbers formed by all root-to-leaf paths in the tree.

  • Input: the root node of a binary tree.
  • Output: an integer representing the sum of all root-to-leaf numbers.

Constraints:

  • Each node value is a digit from 0 to 9.
  • The tree has at most 1000 nodes.

Describe your algorithm and its time and space complexity. You do not need to provide actual code.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Software Engineer•Meta Software Engineer•Meta Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.