PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in data structures and algorithm design by testing binary search tree reconstruction from a preorder sequence and matrix spiral (clockwise layer) traversal.

  • medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Construct a BST and read spiral order

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

The coding round reportedly included two algorithmic tasks: 1. **Rebuild a binary search tree from a preorder sequence** - You are given an array of distinct integers representing the preorder traversal of a binary search tree. - Reconstruct the original tree and return its root. - Aim for a solution that runs in linear time. 2. **Traverse a matrix in clockwise layers** - You are given an `m x n` integer matrix. - Return all elements in the order obtained by repeatedly visiting the current outer boundary clockwise and then shrinking the boundary until every cell has been visited.

Quick Answer: This question evaluates proficiency in data structures and algorithm design by testing binary search tree reconstruction from a preorder sequence and matrix spiral (clockwise layer) traversal.

Rebuild BST From Preorder

Return a nested [value,left,right] BST reconstructed from distinct preorder values.

Constraints

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

Examples

Input: ([8,5,1,7,10,12],)

Expected Output: [8, [5, [1, None, None], [7, None, None]], [10, None, [12, None, None]]]

Explanation: Rebuild BST from preorder using bounds.

Input: ([],)

Expected Output: None

Explanation: Empty preorder returns None.

Hints

  1. Clarify edge cases before coding.
  2. Keep the return value deterministic.

Clockwise Matrix Layer Traversal

Return matrix elements in clockwise spiral layer order.

Constraints

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

Examples

Input: ([[1,2,3],[4,5,6],[7,8,9]],)

Expected Output: [1, 2, 3, 6, 9, 8, 7, 4, 5]

Explanation: Clockwise layer traversal.

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

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

Explanation: Single row works.

Input: ([],)

Expected Output: []

Explanation: Empty matrix returns empty output.

Hints

  1. Clarify edge cases before coding.
  2. Keep the return value deterministic.
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)