PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Return right and left side views of a tree

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of binary tree data structures and the competency to identify side views by reasoning about which node is visible at each depth.

  • medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Return right and left side views of a tree

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Given the root of a binary tree, compute two “side views”: 1. `right_view`: the list of node values visible when looking at the tree from the **right** side, ordered from **top to bottom**. 2. `left_view_reversed`: the list of node values visible when looking at the tree from the **left** side, but ordered from **bottom to top** (i.e., the left side view, then reversed). Return both lists. ## Definitions - The side view at a given depth is the value of the node you would see from that side (i.e., the last node encountered at that depth when scanning from that side). ## Input - `root`: root node of a binary tree. ## Output - A pair/tuple: `(right_view, left_view_reversed)`. ## Constraints - Number of nodes: `0..2*10^5` - Node values fit in 32-bit signed integer. ## Example Tree: ``` 1 / \ 2 3 \ \ 5 4 ``` - `right_view = [1, 3, 4]` - `left_view = [1, 2, 5]` so `left_view_reversed = [5, 2, 1]`

Quick Answer: This question evaluates understanding of binary tree data structures and the competency to identify side views by reasoning about which node is visible at each depth.

Related Interview Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)
Meta logo
Meta
Jan 5, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
2
0
Loading...

Given the root of a binary tree, compute two “side views”:

  1. right_view : the list of node values visible when looking at the tree from the right side, ordered from top to bottom .
  2. left_view_reversed : the list of node values visible when looking at the tree from the left side, but ordered from bottom to top (i.e., the left side view, then reversed).

Return both lists.

Definitions

  • The side view at a given depth is the value of the node you would see from that side (i.e., the last node encountered at that depth when scanning from that side).

Input

  • root : root node of a binary tree.

Output

  • A pair/tuple: (right_view, left_view_reversed) .

Constraints

  • Number of nodes: 0..2*10^5
  • Node values fit in 32-bit signed integer.

Example

Tree:

    1
   / \
  2   3
   \   \
    5   4
  • right_view = [1, 3, 4]
  • left_view = [1, 2, 5] so left_view_reversed = [5, 2, 1]

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

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

Master your tech interviews with 8,000+ 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.