PracHub
QuestionsCoachesLearningGuidesInterview Prep

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.

Given level-order tree values, return [right_view, left_view_reversed].

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([1,2,3,None,5,None,4],)

Expected Output: [[1, 3, 4], [5, 2, 1]]

Explanation: Prompt example shape.

Input: ([],)

Expected Output: [[], []]

Explanation: Empty tree.

Input: ([1,2,None,3],)

Expected Output: [[1, 2, 3], [3, 2, 1]]

Explanation: Left skew.

Hints

  1. Pick a representation that makes the requested operation direct.
  2. Handle empty inputs and boundary cases first.
Last updated: Jun 27, 2026

Loading coding console...

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
  • AI Coding 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.

Related Coding 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)