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
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- Serialize and Deserialize Binary TreeHard · java, python, c, cpp, javascriptSolve Problem
- Boundary TraversalHard · java, python, c, cpp, javascriptSolve Problem
- Vertical Order TraversalHard · java, python, c, cpp, javascriptSolve Problem