107. Maximum Path Sum
Hard
In a binary tree, a path can start and end at any nodes, but it must follow the connections between them without repeating nodes. Return the maximum possible sum of the values along such a path; the tree is not empty.
Example 1
Input: raiz = [-8, 4, 12]
Output: 16
Example 2
Input: raiz = [5, 2, 8, null, null, 6, 10]
Output: 26
Constraints
- 1 <= number of nodes <= 10^4
- -10^4 <= node values <= 10^4
TreesDFSDynamic programming
Saved in this browser
Caso 1
raiz =
[-8,4,12]
Expected =
12
Caso 2
raiz =
[5,2,8,null,null,6,10]
Expected =
25
Run checks these 2 cases. Submit runs all 7, including hidden ones.