Leftmost and rightmost nodes of binary tree
Submissions: 5704   Accuracy:

47.27%

  Difficulty: Medium   Marks: 4

Given a Binary Tree, Print the corner nodes at each level. The node at the leftmost and the node at the rightmost.

Input:
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 intger n denoting the number of edges. The next line contains the edges of the binary tree.

Output:
Print the corner nodes ( nodes at the leftmost and nodes at the rightmost) at each level.

Constraints:
1<=T<=100
1<=data of each node<=100
1<=n<=100

Example:
Input:

2
6
15 10 L 10 8 L 10 12 R 15 20 R 20 16 L 20 25 R
2
1 2 R 2 3 R

Output:
15 10 20 8 25
1 2 3

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

Contributor: Ayush Govil
Author: Ayush Govil 1


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.



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


to report an issue on this page.