 ##### Submissions: 496   Accuracy: 51.01%   Difficulty: Medium   Marks: 4

Given a binary tree with a value associated with each node, we need to choose a subset of these nodes such that sum of chosen nodes is maximum under a constraint that no two chosen node in subset should be directly connected that is, if we have taken a node in our sum then we can’t take its any children in consideration and vice versa. Input Format:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer N denoting the number of edges. The next line contains edges of the binary tree.

Output Format:
Return the maximum sum such that no two nodes are adjacent.

Constraints:
1 <= T <= 100
1 <= N <= 1000

This is a functional problem. User need to complete getMaxSum() function.

Example:
Input:

1
5
1 2 L 1 3 R 2 4 L 3 5 L 3 6 R
Output:
16

Explanation:
Testcase 1: The maximum sum is sum of nodes 1 4 5 6 , i.e 16. These nodes are non adjacent.

#### ** For More Input/Output Examples Use 'Expected Output' option **

Author: SIDG

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.