Neural Mastery
← Back to Practice

Right Side View of a Binary Tree

Difficulty: Medium · Pattern: Tree BFS · Concept: Algorithms & Data Structures — Core Data Structures

Level-Order Traversal flattened an entire tree into one list, level by level. This variant needs BFS to be level-aware, not just level-ordered: imagine standing to the right of the tree — what's the sequence of nodes actually visible? For each level, that's exactly the last node BFS would visit at that depth, and the plain flat-queue approach from Level-Order Traversal has no notion of "where one level ends and the next begins" to make that possible.

Your task: implement right_side_view(root), returning a list of one value per level (the rightmost node's value), top to bottom.

Implement it yourself
assert right_side_view(tree_a) == [1, 3, 4] assert right_side_view(tree_b) == [1, 3] assert right_side_view(tree_c) == [1] assert right_side_view(None) == []

More problems are being added continuously — see Practice Problems overview for the full, current list.

Last updated Sep 5, 2026Edit this pageReport an issue