PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This multi-part question evaluates skills in binary tree traversal and view extraction, vertical column grouping and ordering of tree nodes, and parsing and evaluation of arithmetic expressions with operator precedence and integer division semantics.

  • easy
  • Meta
  • Coding & Algorithms
  • Machine Learning Engineer

Solve Tree Views, Columns, and Calculator

Company: Meta

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Onsite

The interview note referenced three separate coding tasks. Solve each task independently. ### Task 1: Binary tree side views Given the root of a binary tree, return two arrays: - `left_view[d]`: the value of the first node visible at depth `d` when looking at the tree from the left side - `right_view[d]`: the value of the first node visible at depth `d` when looking at the tree from the right side Example: - Input tree: - root = 1 - left child = 2, right child = 3 - node 2 has left child 4 - node 3 has right child 5 - Output: `[[1, 2, 4], [1, 3, 5]]` ### Task 2: Group a binary tree by vertical columns Given the root of a binary tree, assign column `0` to the root. For any node at column `c`, its left child is at column `c - 1` and its right child is at column `c + 1`. Return the node values grouped from the leftmost column to the rightmost column. If multiple nodes fall in the same row and column, output them in left-to-right breadth-first order. Example: - Input tree: - root = 3 - left child = 9, right child = 8 - children of 9 are 4 and 0 - children of 8 are 1 and 7 - Output: `[[4], [9], [3, 0, 1], [8], [7]]` ### Task 3: Evaluate a basic arithmetic string Given a string expression containing non-negative integers, spaces, and the operators `+`, `-`, `*`, and `/`, return the evaluated integer result. - Division truncates toward zero. - The expression contains no parentheses. Example: - Input: `"3+2*2"` - Output: `7` Reasonable constraints for all tasks: - Up to `10^5` nodes for tree problems - Expression length up to `10^5`

Quick Answer: This multi-part question evaluates skills in binary tree traversal and view extraction, vertical column grouping and ordering of tree nodes, and parsing and evaluation of arithmetic expressions with operator precedence and integer division semantics.

Binary Tree Left and Right Side Views

Given level-order tree values, return [left_view, right_view] from top to bottom.

Constraints

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

Examples

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

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

Explanation: Prompt-style shape.

Input: ([],)

Expected Output: [[], []]

Explanation: Empty tree.

Input: ([1],)

Expected Output: [[1], [1]]

Explanation: Single node.

Hints

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

Vertical Column Grouping of a Binary Tree

Group level-order tree values by vertical column from left to right, preserving breadth-first order within each column.

Constraints

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

Examples

Input: ([3,9,8,4,0,1,7],)

Expected Output: [[4], [9], [3, 0, 1], [8], [7]]

Explanation: Prompt example shape.

Input: ([],)

Expected Output: []

Explanation: Empty tree.

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

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

Explanation: Sparse tree.

Hints

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

Basic Calculator Without Parentheses

Evaluate a non-negative integer expression containing +, -, *, / and spaces. Division truncates toward zero.

Constraints

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

Examples

Input: ('3+2*2',)

Expected Output: 7

Explanation: Prompt example.

Input: (' 14-3/2 ',)

Expected Output: 13

Explanation: Truncate division toward zero.

Input: ('2*3+4*5-6',)

Expected Output: 20

Explanation: Mixed precedence.

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)