Given a binary tree, the task is to find the maximum path sum. The path may start and end at any node in the tree.
First line of input contains the number of test cases T. For each test case, there will be only a single line of input which is a string representing the tree as described below:
The values in the string are in the order of level order traversal of the tree where, numbers denotes node values, and a character “N” denotes NULL child.
For the above tree, the string will be: 1 2 3 N N 4 6 N 5 N N 7 N
Print the maximum path sum in the binary tree.
The task is to complete the findMaxSum() that takes root as input and returns max sum.
1 <= T <= 100
1 <= Number of nodes <= 103
1 <= |Data on node| <= 104
10 2 -25 20 1 3 4
10 2 5 N N N -2
Testcase 2: Path in the given tree goes like 2, 10, 5, which gives the max sum as 17.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.