Leftmost and rightmost nodes of binary tree

0

0 votes
Easy-Medium
Problem

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 Nodes(except Root). The next line contains the nodes 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

Sample 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
Sample Output
15 10 20 8 25
1 2 3
Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?