PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Implement solutions to several coding tasks

Last updated: Mar 29, 2026

Quick Overview

This multipart prompt evaluates algorithmic problem-solving and data-structure design skills across several areas: finding a minimum in a rotated sorted array (binary search), implementing a time-based key-value store, computing lowest common ancestor in a binary tree, and marking a path on a 2D maze.

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

Implement solutions to several coding tasks

Company: Meta

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given several independent coding interview tasks. Solve each with the required time/space complexity. ## Problem 1: Find the minimum in a rotated sorted array You are given an array `nums` of **distinct** integers that was originally sorted in increasing order and then rotated at an unknown pivot (e.g., `[4,5,6,7,0,1,2]`). - **Input:** `nums: int[]` - **Output:** the minimum value in `nums` - **Constraints:** `1 ≤ len(nums) ≤ 2e5` - **Expected complexity:** `O(log n)` time, `O(1)` extra space ## Problem 2: Time-based key-value store (variation) Design a data structure that supports storing and querying values for a key over time. Support the following operations: - `set(key: string, value: string, timestamp: int) -> void` - Stores the value for `key` at the given timestamp. - `get(key: string, timestamp: int) -> string` - Returns the value associated with `key` at the **largest timestamp ≤ query timestamp**. - If there is no such timestamp for the key, return an empty string. Assumptions/constraints: - Timestamps are integers. - For the same key, `set()` calls may arrive in increasing timestamp order (state your assumption); handle the general case if not. - Target: near `O(log m)` per `get()` for `m` versions of a key. ## Problem 3: Lowest common ancestor in a binary tree Given the root of a binary tree and two nodes `p` and `q` that both exist in the tree, return their **lowest common ancestor (LCA)**. - The LCA of `p` and `q` is the lowest node in the tree that has both `p` and `q` as descendants (a node can be a descendant of itself). ## Problem 4: Mark a path on a maze You are given: - A 2D maze grid `maze` represented as a list of equal-length strings. - `'#'` = wall - `'.'` = open cell - `'e'` = entrance (must stay as `'e'`) - `'E'` = exit (must stay as `'E'`) - A list `path` of coordinates (row, col) representing a valid path through the maze **including the entrance and exit**. Write a function that returns a new maze where every coordinate in `path` is replaced with `'*'`, **except** the entrance `'e'` and exit `'E'`, which must not be changed. - **Input:** `maze: string[]`, `path: (int row, int col)[]` - **Output:** `string[]` (the updated maze) - You may assume `path` contains only in-bounds coordinates and forms a valid path through open cells.

Quick Answer: This multipart prompt evaluates algorithmic problem-solving and data-structure design skills across several areas: finding a minimum in a rotated sorted array (binary search), implementing a time-based key-value store, computing lowest common ancestor in a binary tree, and marking a path on a 2D maze.

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

You are given several independent coding interview tasks. Solve each with the required time/space complexity.

Problem 1: Find the minimum in a rotated sorted array

You are given an array nums of distinct integers that was originally sorted in increasing order and then rotated at an unknown pivot (e.g., [4,5,6,7,0,1,2]).

  • Input: nums: int[]
  • Output: the minimum value in nums
  • Constraints: 1 ≤ len(nums) ≤ 2e5
  • Expected complexity: O(log n) time, O(1) extra space

Problem 2: Time-based key-value store (variation)

Design a data structure that supports storing and querying values for a key over time.

Support the following operations:

  • set(key: string, value: string, timestamp: int) -> void
    • Stores the value for key at the given timestamp.
  • get(key: string, timestamp: int) -> string
    • Returns the value associated with key at the largest timestamp ≤ query timestamp .
    • If there is no such timestamp for the key, return an empty string.

Assumptions/constraints:

  • Timestamps are integers.
  • For the same key, set() calls may arrive in increasing timestamp order (state your assumption); handle the general case if not.
  • Target: near O(log m) per get() for m versions of a key.

Problem 3: Lowest common ancestor in a binary tree

Given the root of a binary tree and two nodes p and q that both exist in the tree, return their lowest common ancestor (LCA).

  • The LCA of p and q is the lowest node in the tree that has both p and q as descendants (a node can be a descendant of itself).

Problem 4: Mark a path on a maze

You are given:

  • A 2D maze grid maze represented as a list of equal-length strings.
    • '#' = wall
    • '.' = open cell
    • 'e' = entrance (must stay as 'e' )
    • 'E' = exit (must stay as 'E' )
  • A list path of coordinates (row, col) representing a valid path through the maze including the entrance and exit .

Write a function that returns a new maze where every coordinate in path is replaced with '*', except the entrance 'e' and exit 'E', which must not be changed.

  • Input: maze: string[] , path: (int row, int col)[]
  • Output: string[] (the updated maze)
  • You may assume path contains only in-bounds coordinates and forms a valid path through open cells.

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.