Sum numbers formed by root-to-leaf paths
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
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.
Constraints
- Each node value is a digit 0..9; None represents a missing node
Examples
Input: ([1, 2, 3],)
Expected Output: 25
Explanation: 12 + 13.
Input: ([4, 9, 0, 5, 1],)
Expected Output: 1026
Explanation: 495 + 491 + 40.
Input: ([],)
Expected Output: 0
Explanation: Empty tree.
Input: ([0, 1],)
Expected Output: 1
Explanation: Leading zero path.
Hints
- Carry the current prefix value during DFS.