PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Solve Tree Views, Columns, and Calculator

Last updated: Mar 29, 2026

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.

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
Feb 27, 2026, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
2
0
Loading...

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

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Machine Learning Engineer•Meta Machine Learning Engineer•Meta Coding & Algorithms•Machine Learning 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.