Maximum Path Sum in Binary Tree
Hardjavapythonccppjavascript
Find the maximum sum obtainable along any path in a binary tree. A path is a sequence of nodes where consecutive nodes are connected by an edge; it may start and end at any node and need not pass through the root.
Input Format
The first line contains an integer M, the number of level-order tokens. The second line contains M space-separated tokens (integers or null).
Output Format
Print the maximum path sum.
Example 1
Input
7 -10 9 20 null null 15 7
Output
42
Explanation: The path 15 -> 20 -> 7 gives the maximum sum 42.
- 1 <= number of nodes <= 5000
- -1000000000 <= node value <= 1000000000