Return the values visible when a binary tree is viewed from the right side.
Given the root of a binary tree, imagine standing to the right of the tree and looking toward it. Return the list of node values that are visible from top to bottom.
At each depth, only the rightmost node is visible.
Produce the values of the visible nodes in order from the top level to the deepest level.
Example 1
Input
root = [1,2,3,null,5,null,4]
Output
[1,3,4]
Explanation
At depth 0, 1 is visible. At depth 1, 3 hides 2 from the right view. At depth 2, 4 is visible.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.