Skip to main content
Back to problems
Leetcode
Medium
Trees
Queues
Recursion
Google
Binary Tree Right Side View

Return the values visible when a binary tree is viewed from the right side.

Acceptance 0%
Problem Statement

Problem

Given the root of a binary tree, imagine standing to the right of the tree and looking toward it. Return the list of node values that are visible from top to bottom.

At each depth, only the rightmost node is visible.

Goal

Produce the values of the visible nodes in order from the top level to the deepest level.

Input Format

  • The input is the root of a binary tree.
  • Each node contains an integer value and pointers to its left and right child.

Output Format

  • Return an array of integers representing the right side view of the tree from top to bottom.

Constraints

  • The tree may be empty.
  • Node values can be any valid integer.
  • A correct solution should run in linear time relative to the number of nodes.
Examples
Sample cases returned by the problem API.

Example 1

Input

root = [1,2,3,null,5,null,4]

Output

[1,3,4]

Explanation

At depth 0, 1 is visible. At depth 1, 3 hides 2 from the right view. At depth 2, 4 is visible.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.