PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Return all root-to-leaf path sums

Last updated: Mar 29, 2026

Quick Overview

This question evaluates competency in binary tree traversal and path-state accumulation, focusing on the ability to compute sums along root-to-leaf paths while handling edge cases like empty trees and negative values.

  • medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Return all root-to-leaf path sums

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Problem You are given the root of a **binary tree** where each node contains an integer value (may be negative). Return an array/list containing the **sum of values along every path from the root to a leaf** (a leaf is a node with no children). ## Input - `root`: root node of a binary tree. ## Output - A list of integers, where each integer is the sum of one root-to-leaf path. - The order of sums can be any consistent traversal order (e.g., DFS order). ## Examples 1) Tree: ``` 5 / \ 4 8 / \ 11 4 ``` Root-to-leaf sums are: - 5→4 = 9 - 5→8→11 = 24 - 5→8→4 = 17 Output (one valid): `[9, 24, 17]` 2) Single node `-3` → output `[-3]` ## Constraints (typical interview assumptions) - Number of nodes: up to ~10^4 - Node values fit in 32-bit signed integer ## Notes - If the tree is empty, return an empty list.

Quick Answer: This question evaluates competency in binary tree traversal and path-state accumulation, focusing on the ability to compute sums along root-to-leaf paths while handling edge cases like empty trees and negative values.

Related Interview Questions

  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)
  • Solve a Key-Door Corridor Maze - Meta (medium)
  • Solve Array Merge and Parentheses Cleanup - Meta (medium)
Meta logo
Meta
Dec 15, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
1
0

Problem

You are given the root of a binary tree where each node contains an integer value (may be negative).

Return an array/list containing the sum of values along every path from the root to a leaf (a leaf is a node with no children).

Input

  • root : root node of a binary tree.

Output

  • A list of integers, where each integer is the sum of one root-to-leaf path.
  • The order of sums can be any consistent traversal order (e.g., DFS order).

Examples

  1. Tree:
    5
   / \
  4   8
     / \
    11  4

Root-to-leaf sums are:

  • 5→4 = 9
  • 5→8→11 = 24
  • 5→8→4 = 17 Output (one valid): [9, 24, 17]
  1. Single node -3 → output [-3]

Constraints (typical interview assumptions)

  • Number of nodes: up to ~10^4
  • Node values fit in 32-bit signed integer

Notes

  • If the tree is empty, return an empty list.

Submit Your Answer

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 8,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.