At Amazon,
our delivery route optimization often involves tree-like structures.
Here's an interesting problem that reflects
similar patterns:
Given a binary tree where:
Each node contains a single digit (0-9)
Each path from root to leaf represents
a number
For example: path 4+2+1 represents number 421
Write a function to compute the sum of all numbers represented by root-to-leaf paths.
Input: root - [1,2,3]
1
2 3
Output: 25
Input: root - [4,9,0,5,1]
Output: 1026
4
9. 0
5. 1