Binary Tree Right Side View
On this page
Problem statement
Given the root of a binary tree, imagine standing to its right and looking left. Return the values you can see, from top to bottom. On each level you see exactly one node: the one furthest to the right on that level.
A short, popular tree question. It checks whether you think in levels rather than in "go right". Original problem: LeetCode 199.
Example

Input: root = [1, 2, 3, 4, 5, null, null, null, null, 6]
Output: [1, 3, 5, 6]
Input: root = [1, null, 3]
Output: [1, 3]
Input: root = []
Output: []
Constraints (assumed)
- 0 ≤ number of nodes ≤ 100.
- −100 ≤ node value ≤ 100.
What this question tests
- Level-order traversal (BFS) with clean level boundaries.
- Noticing that the visible node on a level can come from the left subtree.
- Knowing a DFS alternative and comparing the space each one uses.
Questions to ask first
- What should an empty tree return? (An empty list.)
- Top to bottom order? (Yes, one value per level, root first.)
- Is it really one node per level, the rightmost? Some versions ask for both the left and right views; confirm which.
- How big can the tree be? For a very deep tree, recursion depth matters for the DFS version.
Try it yourself first
You have the full problem. Sketch your answer, then sign up free to read the complete walkthrough.
- The complete design, flow by flow, with pictures
- Deep dives into the hard parts
- What mid, senior and staff candidates are expected to say
- Full company question lists
Free forever. No card needed.