hard

Binary Tree Maximum Path Sum

A path in a binary tree is a sequence of adjacent nodes with no repeats; it need not pass through the root. Given the root of a tree whose values may be negative, return the maximum sum of values along any path.

Constraints
  • 1 ≤ number of nodes ≤ 3 · 10^4
  • -1000 ≤ node value ≤ 1000
Examples
in: root = [-10,9,20,null,null,15,7]
out: 42
15 → 20 → 7.

Code it yourself

Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?

Choose an approach to check your pattern recognition, or reveal the discussion when you need help.