Solve Tree Views, Columns, and Calculator
Company: Meta
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Onsite
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
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
- Pick a representation that makes the requested operation direct.
- Handle empty inputs and boundary cases first.
Vertical Column Grouping of a Binary Tree
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
- Pick a representation that makes the requested operation direct.
- Handle empty inputs and boundary cases first.
Basic Calculator Without Parentheses
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
- Pick a representation that makes the requested operation direct.
- Handle empty inputs and boundary cases first.