PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates understanding of binary tree data structures and the competency to aggregate values along root-to-leaf paths, combining tree traversal with numeric accumulation of node digits.

  • medium
  • Bytedance
  • Coding & Algorithms
  • Software Engineer

Compute root-to-leaf number sum

Company: Bytedance

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given the root of a binary tree where each node stores a digit from `0` to `9`, every root-to-leaf path represents a decimal number formed by concatenating the digits along the path. Return the sum of all numbers represented by every root-to-leaf path. A leaf is a node with no children. Example: - Input tree: `[4,9,0,5,1]` - Root-to-leaf numbers: `495`, `491`, and `40` - Output: `1026` Function signature (language-agnostic): `int sumRootToLeafNumbers(TreeNode root)` Constraints: - The number of nodes is in the range `[0, 1000]`. - `0 <= node.val <= 9`.

Quick Answer: This question evaluates understanding of binary tree data structures and the competency to aggregate values along root-to-leaf paths, combining tree traversal with numeric accumulation of node digits.

Given level-order digit tree values, sum all root-to-leaf numbers.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([4,9,0,5,1],)

Expected Output: 1026

Explanation: Prompt example.

Input: ([],)

Expected Output: 0

Explanation: Empty tree.

Input: ([1,2,3],)

Expected Output: 25

Explanation: Two root-leaf numbers.

Hints

  1. Model object-style prompts as operation streams when needed.
  2. Handle empty and boundary cases before the main logic.
Last updated: Jun 27, 2026

Loading coding console...

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
  • AI Coding 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.

Related Coding Questions

  • Elements Occurring More Than n/3 Times in a Sorted Array - Bytedance (medium)
  • Least Frequently Used (LFU) Cache - Bytedance (hard)
  • Course Schedule Feasibility - Bytedance (hard)
  • Find the Best Word for a Query Suffix - Bytedance (hard)
  • Reverse a Singly Linked List - Bytedance (medium)