Binary Tree Right Side View
Problem
Imagine standing to the right of a binary tree and looking at it side-on. At each depth you see exactly one node: the rightmost node on that level, whether or not it is a right child. Given the root, return the values of the visible nodes ordered from the top level down. Return an empty list for an empty tree.
- The tree has at most 3,000 nodes and may be empty.
- Node values are integers; duplicates are allowed.
Examples
root = [8, 3, 10, None, 6, None, 14]→[8, 10, 14]. At each depth the rightmost node happens to be on the right spine.root = [8, 3, 10, 1, None, None, None, 4]→[8, 10, 1, 4]. The 1 and the 4 are left children, but each is the only node on its level, so both are visible from the right.root = [2, None, 6]→[2, 6].
Hints
- Which node on each level is visible? Is it always reachable by only following right pointers?
- If you had all the nodes grouped by level, the answer is one element from each group.
- Level-order BFS and take the last node of each level; or a pre-order DFS that visits the right child first and records the first node it reaches at each new depth.
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.