Maximum Sum Path of Binary Tree
- You are given a binary tree having 'N' nodes. Each node of the tree has an integer value. Your task is to find the maximum possible sum of a simple path between any two nodes (possibly same) of the given tree.
- A simple path is a path between any two nodes of a tree, such that no edge in the path is repeated twice. Sum of a simple path is defined as the summation of all node values in a path.
Input Format
- The only line of each test case contains elements in the level order form. The line consists of values of nodes separated by a single space. In case a node is null, we take -1 on its place.
Constraints
Time:- 1 Sec
Output Format
Print the output .
Sample Input 0
1 2 3 4 -1 -1 -1 -1 -1
Sample Output 0
10
Sample Input 1
2 4 -1 3 6 -1 -1 -1 -1
Sample Output 1
13
Loading Editor...