Maximum path sum between two leaves of a binary tree

Given a binary tree, such that each node contains a number. Find the maximum possible sum in going from one leaf node to another.

Example: The maximum sum path may or may not go through root. For example, in the following binary tree, the maximum sum is 27(3 + 6 + 9 + 0 – 1 + 10). Expected time complexity is O(n).

                                             

Author: Amit Khandelwal 1
Login to Answer
Sort By:
Oldest
|
Newest
|
Vote
|
My Answer