Pattern Recognition Drill
Medium Advanced Trees
The Problem
Return values visible from the right side (rightmost node per level).
What approach would you use?
Think about it before scrolling down.
Level-order BFS. For each level, the last node is the rightmost. O(n).
DFS visiting right before left. First node at each new depth is the answer. O(n).
Common Trap
It's not just the rightmost branch — nodes from the left can appear if right subtree is shorter.