Back to DSA
Binary Tree Maximum Path Sum
hardIn a binary tree, a path is any sequence of connected nodes traveling parent-child edges, where no node appears more than once. The path need not include the root. Compute the highest possible sum of node values along any such path in the tree.
Examples
Example 1:
Input:
root = [2,1,4]Output:
7Explanation: The path 1 -> 2 -> 4 yields the maximum sum of 7.
Example 2:
Input:
root = [-5,8,12,null,null,10,3]Output:
25Explanation: The path 10 -> 12 -> 3 sums to 25.
Hints
1234567