BETA

Difficulty Level:

Easy

Total Submissions: 1619 Accuracy:

48.18%

Vertical sum (Function Problem)
     

Given a Binary Tree, find vertical sum of the nodes that are in same vertical line. Print all sums through different vertical lines.

Input:
First line of every test case consists of T test case. First line of every test case consists of N, denoting number of nodes. Second line of every test case consists of 3*N elements denoting , 2 integers and 1 character ,i.e., parent node , child node and character denotes which child.

Output:
Single line output, print the vertical sum from left to right.

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

Example:
Input:

2
3
5 2 L 5 3 R 2 1 L
5
5 3 R 5 2 L 2 1 L 2 7 R 3 6 L
Output:
1 2 5 3 
1 2 18 3 

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

Contributor: Saksham Raj Seth


					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.