Picture a binary tree drawn top-down and look at it from the right-hand side. On each level you see only the node furthest to the right; every other node on that level is hidden behind it.
Given the root of a binary tree, return the values you can see, one per level, from the top level down. An empty tree shows nothing, so its answer is an empty list.
9 hides 3 on the second level. The third level has no right-hand branch at all, so the rightmost node there is 5, inside the left subtree, and 4 below it is visible too.
3 is a left child, but it is alone on its level, so nothing hides it.
Constraints
0 and 100 nodes.-100 <= Node.val <= 100The answer holds one value per level: the last node on that level when you read it left to right.
The answer has one value per level: the node furthest to the right on that level. So the question is really "which node is last on each level?"
Time O(n)Space O(w)
The full walkthrough and code are part of Premium