Simple tree with positive values
Input
Tree: 1 / \ 2 3
Output
6
The best path is 2 -> 1 -> 3 with sum 2 + 1 + 3 = 6.
Full lesson preview
Compute the maximum sum obtainable by any path in a binary tree (path may start and end at any nodes).
Problem statement
Task
Examples
Input
Tree: 1 / \ 2 3
Output
6
The best path is 2 -> 1 -> 3 with sum 2 + 1 + 3 = 6.
Input format
Output format
Constraints
Samples
Input
Tree: [ -10, 9, 20, null, null, 15, 7 ]
Output
42
The maximum path is 15 -> 20 -> 7 = 42 (through node 20).