Max Sum Path in Binary Tree

Given a binary tree T, find the maximum path sum.

The path may start and end at any node in the tree.

Input Format:

The first and the only argument contains a pointer to the root of T, A.

Output Format:

Return an integer representing the maximum sum path.


1 <= Number of Nodes <= 7e4
-1000 <= Value of Node in T <= 1000

Example :

Input 1:

      / \
     2   3

Output 1:

Explanation 1:
    The path with maximum sum is: 2 -> 1 -> 3

Input 2:
       /  \
     -20  -30

Output 2:

Explanation 2
    The path with maximum sum is: -10
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Max Sum Path in Binary Tree on Interview Code Editor
  • Hint 1
  • Solution Approach
  • Complete Solution
Asked In:


Click here to start solving coding interview questions