Given the root of a binary tree, return the values of the nodes visible from the right side, from top to bottom. Pattern focus: Preorder DFS (Root First). Visit the right subtree before the left subtree to capture the first visible node at each depth.
root = binary tree root
values visible from the right side
Example 1:
Input:
root = [1,2,3,null,5,null,4]
Output:
[1,3,4]
Explanation:
At each level, the rightmost node is visible.
Example 2:
Input:
root = [1,null,3]
Output:
[1,3]
Explanation:
The rightmost path is directly visible.