← All problems

Binary Tree Maximum Path Sum

Hard treesrecursiondynamic programming LeetCode ↗
Find the maximum path sum in a binary tree, where a path is any sequence of nodes connected by parent-child edges and may start and end at any nodes. Node values may be negative.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n), Space O(h)

Common pitfalls

  • Allowing negative contributions downward (clamp at 0)
  • Confusing return value with global answer

Your solution

Log in to save your code and track progress.