Imagine standing on the right side of a binary tree. Return the values of the nodes you can see, ordered from top to bottom.
This is a BFS variation — at each level, the last node is what you see from the right:
Time: O(n), Space: O(n). A simple twist on level-order traversal!
right_side_view(root)
[1, 3, 4]
right_side_view(TreeNode(1, TreeNode(2)))
[1, 2]