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.

Constraints:

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

Example :

Input 1:

       1
      / \
     2   3

Output 1:
     6

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

Input 2:
    
       -10
       /  \
     -20  -30

Output 2:
    -10

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
Sign Up
to access hints and editorial solutions for Max Sum Path in Binary Tree
Asked In:

Discussion


Loading...
Click here to start solving coding interview questions