There are different ways to look at a binary tree. The right view of a binary tree contains the set of nodes that will be visible if you look at the binary tree from the right side.
Given the root node of a binary tree, return an array containing the node elements in the right view, from top to bottom.
The first line contains an integer T denoting the number of test cases.
For each test case, the input has 2 lines:
For each test case, the output contains a line with space-separated integers representing the right view of the binary tree.
6
7
1 2 -1 4 -1 5 6
3
6 -1 4
7
8 -1 9 -1 10 11 12
5
28 14 11 -1 48
1
6
7
3 -1 2 1 5 -1 6
1 2 4 6
6 4
8 9 10 12
28 11 48
6
3 2 5 6
1 <= T <= 10
1 <= n <= 105
1 <= node value <= 106