Quick Overview

This question evaluates understanding of binary tree traversal and level-order reasoning, including distinctions between recursive and iterative approaches and handling of edge cases such as skewed or missing children.

Compute binary tree left-side view

Company: Meta

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Given a binary tree, return the values visible from the left side when looking from top to bottom. If multiple nodes exist at the same depth, the leftmost node is visible. Provide iterative (level-order) and recursive solutions, discuss time and space complexity, and handle skewed trees and missing children.

Overview: This question evaluates understanding of binary tree traversal and level-order reasoning, including distinctions between recursive and iterative approaches and handling of edge cases such as skewed or missing children.

Given level-order tree values, return the leftmost visible value at each depth.

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, 2, 5]

Explanation: Left view through sparse tree.

Input: ([],)

Expected Output: []

Explanation: Empty tree.

Hints

  1. Choose a representation that makes the requested operation direct.
  2. Handle empty inputs and boundary cases first.

Binary Tree Left-Side View

mediumMetaMachine Learning Engineer

Given level-order tree values, return the leftmost visible value at each depth.

Examples

Example 1
Input
([1,2,3,None,5,None,4],)
Output
[1, 2, 5]
Notes
Left view through sparse tree.
Example 2
Input
([],)
Output
[]
Notes
Empty tree.

Constraints

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

Comments (0)

No comments yet. Be the first to comment!

Submit your answer

Approved first answer today earns 30 XP
Bold⌘BItalic⌘IInline code⌘`Bullet listTab to nest (○ ■)Numbered listTab to nest (a. i.)QuoteCode block
Formatting help
Sample call
solution([1,2,3,None,5,None,4])
Language
Case 1
Input
([1,2,3,None,5,None,4],)
Expected
[1, 2, 5]
Case 2
Input
([],)
Expected
[]

Browse More Questions