Breadth-First Search
Medium

Binary Tree Rightmost Node (Right Side View)

Return the values of the nodes you can see ordered from top to bottom.
Problem Understanding

Given the root of a binary tree, imagine yourself standing on the right side of it. Return the values of the nodes you can see ordered from top to bottom.

  • Essentially: For every level, pick the last node.
Algorithm Strategy

We can use BFS (Level Order Traversal).

  1. Process the tree level by level.
  2. For each level, the last node in the queue (before moving to the next level) is the rightmost node.
  3. Add that node's value to our result list.
Interactive Visualization
Step 1 / 1
Empty Heap

Initializing...

1x
See the Logic in Motion
Stop memorizing code. Unlock the full interactive visualizer to master the logic step-by-step.
Unlock VisualizerPREMIUM FEATURE

Stop Guessing, Start Mastering.

Build the FAANG intuition. Master this pattern with optimized implementations, visual dry runs, and our curated collection of high-yield problems.

Start Your Premium Prep