PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Google

Find right-side view of binary tree

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of binary tree structures and traversal techniques, specifically reasoning about the right-side view by depth, along with the ability to analyze time and space complexity.

  • easy
  • Google
  • Coding & Algorithms
  • Software Engineer

Find right-side view of binary tree

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are given the root of a binary tree. From the **right side** of the tree, at each depth you can see exactly one node: the rightmost node at that depth. Write a function that returns a list of the values of the nodes visible when looking at the tree from the right side, ordered from **top to bottom**. --- ### Function Signature (one possible form) ```text rightSideView(root: TreeNode) -> List[int] ``` Where `TreeNode` is defined as: ```text class TreeNode { int val; TreeNode left; TreeNode right; } ``` --- ### Example Consider this binary tree: ```text 1 / \ 2 3 \ \ 5 4 ``` The right-side view is: ```text [1, 3, 4] ``` Explain the algorithm you would use, including its time and space complexity. You may use either breadth-first search (BFS) or depth-first search (DFS).

Quick Answer: This question evaluates understanding of binary tree structures and traversal techniques, specifically reasoning about the right-side view by depth, along with the ability to analyze time and space complexity.

Related Interview Questions

  • Solve Flower Placement and Directory Deletion - Google (medium)
  • Compute Turnstile Crossing Times - Google (hard)
  • Simulate In-Place Cellular State Updates - Google (hard)
  • Determine Whether a Word Exists in a Graph - Google (medium)
  • Implement Checksums and Feature Rollout Evaluation - Google (medium)
Google logo
Google
Nov 1, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
3
0

You are given the root of a binary tree.

From the right side of the tree, at each depth you can see exactly one node: the rightmost node at that depth.

Write a function that returns a list of the values of the nodes visible when looking at the tree from the right side, ordered from top to bottom.

Function Signature (one possible form)

rightSideView(root: TreeNode) -> List[int]

Where TreeNode is defined as:

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
}

Example

Consider this binary tree:

    1
   / \
  2   3
   \   \
    5   4

The right-side view is:

[1, 3, 4]

Explain the algorithm you would use, including its time and space complexity. You may use either breadth-first search (BFS) or depth-first search (DFS).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Software Engineer•Google Software Engineer•Google Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.