Binary Tree Maximum Path Sum Problem
Binary Tree Maximum Path Sum Problem — ExecCode Hard DSA Practice
Solve the Binary Tree Maximum Path Sum problem on ExecCode. Free online hard DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
A path in a binary tree is a sequence of nodes where each pair of adjacent nodes has an edge connecting them. A node can only appear in the sequence at most once. The path sum of a path is the sum of the node's values in the path. Given the root of a binary tree, return the maximum path sum of any non-empty path.
Examples
Input root = [-10, 9, 20, -5, 4, 15, 7, -3]; Output 42. Input root = [1, 2, 3]; Output 6. Input root = [-3]; Output -3
Constraints
The number of nodes in the tree is in the range [1, 3 * 10^4]. -1000 <= Node.val <= 1000
Practice Binary Tree Maximum Path Sum free on ExecCode. Browse DSA problems, topic map, and placement guides.