Browse Curriculum
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

Watch BFS collecting the last element of every level.

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.