Hard · Trees
Binary Tree Maximum Path Sum
Given the root of a non-empty binary tree, return the maximum path sum, where a path is a sequence of nodes joined by parent–child edges that uses each node at most once, contains at least one node, and need not pass through the root.
Examples
Example 1
[-10,9,20,null,null,15,7] → 42Output: max path = 42
Example 2
[1,2,3] → 6Output: max path = 6
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.