Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Binary Tree Maximum Path Sum

XPChallenge Points: 30
levelLevel: Hard

In a binary tree, a path is any sequence of connected nodes where each node appears only once.
The path does not have to go through the root.
The path sum is the total of all node values along that path.
Return the highest possible path sum for any non-empty path in the tree.

Example 1:

Input: root = [5,4,8,11,null,13,4]

Output: 48

Explanation:

The best path is 11 → 4 → 5 → 8 → 13 with a sum of 48.

Example 2:

Input: root = [-3]

Output: -3

Explanation:

Only one node exists, so the maximum path sum is -3.

Example 3:

Input: root = [10,2,10,20,1,-25,3,4]

Output: 42

Explanation:

The best path is 20 → 2 → 10 → 10, giving a sum of 42.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result