PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Solve maze reachability and two follow-ups

Last updated: Mar 29, 2026

Quick Overview

This set of tasks evaluates graph and state-space search with constrained movement (maze rolling ball), tree algorithms and recursion for computing diameter, and stack-based simulation with log parsing for exclusive time accounting, all within the Coding & Algorithms domain and testing algorithmic problem-solving and data structure usage.

  • medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Solve maze reachability and two follow-ups

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given three independent coding tasks. ## 1) Maze reachability with “rolling ball” movement Given an `m x n` grid `maze` where `0` means empty and `1` means wall, a ball starts at `start = (sr, sc)` and wants to reach `destination = (dr, dc)`. Movement rule: from any cell, you may choose one of 4 directions (up/down/left/right). The ball then **rolls** in that direction until the next step would hit a wall or go out of bounds; it **stops at the last valid empty cell** before the obstacle. You may then choose a new direction. Return whether the ball can stop **exactly** at `destination`. **Input:** `maze: int[m][n]`, `start: int[2]`, `destination: int[2]` **Output:** `bool` **Constraints (typical):** `1 ≤ m,n ≤ 100`, `maze[i][j] ∈ {0,1}`, start/destination are empty. ## 2) Compute the diameter of a binary tree Given the root of a binary tree, compute its **diameter**, defined as the maximum number of **edges** on any path between two nodes in the tree. **Input:** `root` (binary tree) **Output:** `int` ## 3) Exclusive time of functions from logs There are `n` single-threaded functions labeled `0..n-1`. You are given a list of logs in chronological order. Each log is a string in the format: - `"id:start:timestamp"` or - `"id:end:timestamp"` Rules: - A function can call other functions; the CPU executes only the top of the call stack. - `end:timestamp` is **inclusive** (i.e., the function runs through that timestamp). Return an array `ans` where `ans[i]` is the **exclusive** time spent in function `i`. **Input:** `n: int`, `logs: string[]` **Output:** `int[]` **Constraints (typical):** `1 ≤ n ≤ 100`, `1 ≤ logs.length ≤ 10^4`, timestamps are non-decreasing integers.

Quick Answer: This set of tasks evaluates graph and state-space search with constrained movement (maze rolling ball), tree algorithms and recursion for computing diameter, and stack-based simulation with log parsing for exclusive time accounting, all within the Coding & Algorithms domain and testing algorithmic problem-solving and data structure usage.

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 7, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
11
0
Loading...

You are given three independent coding tasks.

1) Maze reachability with “rolling ball” movement

Given an m x n grid maze where 0 means empty and 1 means wall, a ball starts at start = (sr, sc) and wants to reach destination = (dr, dc).

Movement rule: from any cell, you may choose one of 4 directions (up/down/left/right). The ball then rolls in that direction until the next step would hit a wall or go out of bounds; it stops at the last valid empty cell before the obstacle. You may then choose a new direction.

Return whether the ball can stop exactly at destination.

Input: maze: int[m][n], start: int[2], destination: int[2]

Output: bool

Constraints (typical): 1 ≤ m,n ≤ 100, maze[i][j] ∈ {0,1}, start/destination are empty.

2) Compute the diameter of a binary tree

Given the root of a binary tree, compute its diameter, defined as the maximum number of edges on any path between two nodes in the tree.

Input: root (binary tree)

Output: int

3) Exclusive time of functions from logs

There are n single-threaded functions labeled 0..n-1. You are given a list of logs in chronological order.

Each log is a string in the format:

  • "id:start:timestamp" or
  • "id:end:timestamp"

Rules:

  • A function can call other functions; the CPU executes only the top of the call stack.
  • end:timestamp is inclusive (i.e., the function runs through that timestamp).

Return an array ans where ans[i] is the exclusive time spent in function i.

Input: n: int, logs: string[]

Output: int[]

Constraints (typical): 1 ≤ n ≤ 100, 1 ≤ logs.length ≤ 10^4, timestamps are non-decreasing integers.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

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