TreeBFSDFS
Imagine standing to the right of a binary tree. List the values of the nodes you can see, from top to bottom (the last node of each level). Build the tree from the level-order input yourself, then solve the problem.
Input
A single line giving the tree in level order, with the word null for a missing child (for example 3 9 20 null null 15 7).
Output
Print the visible values on one line, top to bottom.
Constraints
1 <= number of nodes <= 2000
Example 1
Input
1 2 3 null 5 null 4
Output
1 3 4
From the right you see 1, 3 and 4.