Loading...
Loading...
Loading...
Stand to the right of the tree and look at it. At each level you see only the last node. Print those values from the top down, separated by spaces.
Example 1
Input
1 2 3 null 5 null 4
Output
1 3 4
You see 1, then 3, then 4.
Example 2
Input
8
Output
8
Try the problem first. Open one hint at a time.
Collect the levels, then take the last value of each.
A left child is still seen when the right side of that level is empty.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor