Geeksforgeeks

Error

Given a Binary Tree, find the maximum sum path from a leaf to root.

**Example 1:**

Input:1 / \ 2 3Output:4Explanation:Following the path 3 -> 1, results in a sum of 4, which is the maximum path sum from leaf to root for the given tree.

**Example 2:**

Input:10 / \ -2 7 / \ 8 -4Output:17Explanation :Following the path 7 -> 10, results in a sum of 17, which is the maximum path sum from leaf to root for the given tree.

You don't need to read input or print anything. Your task is to complete the function **maxPathSum()** which takes the root node of the tree as input and returns an integer denoting the maximum possible leaf to root path sum.

1 <= Number of nodes <= 10^5

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Maximum sum leaf to root path

...