← Queue / BFS

Pattern Recognition Drill

#93 — Binary tree right side view

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.

Key Signals

Queue / BFS

Level-order BFS. For each level, the last node is the rightmost. O(n).

Alt: DFS / Recursion

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.

← #92 #94 →