PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Meta

Find shortest path in a maze grid

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in graph traversal and shortest-path reasoning on grid-based data structures, testing skills in pathfinding, state-space modeling, and algorithmic complexity within the Coding & Algorithms domain.

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

Find shortest path in a maze grid

Company: Meta

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Maze shortest path You are given a 2D grid `maze` of size `m x n` where: - `0` represents an open cell - `1` represents a wall (cannot pass) You are also given a start cell `(sr, sc)` and a target cell `(tr, tc)`. From any open cell, you may move **up, down, left, or right** by 1 step (no diagonals), staying within bounds. ### Task Return the **minimum number of steps** required to reach the target from the start. If it is impossible, return `-1`. ### Input/Output - **Input:** `maze: int[][]`, `start: int[2]`, `target: int[2]` - **Output:** `int` (minimum steps or `-1`) ### Assumptions / Constraints - `1 <= m, n <= 200` - `maze[sr][sc] == 0` and `maze[tr][tc] == 0` - The grid may be large enough that an efficient graph traversal is required.

Quick Answer: This question evaluates proficiency in graph traversal and shortest-path reasoning on grid-based data structures, testing skills in pathfinding, state-space modeling, and algorithmic complexity within the Coding & Algorithms domain.

Related Interview Questions

  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve a Key-Door Corridor Maze - Meta (medium)
  • Solve Array Merge and Parentheses Cleanup - Meta (medium)
  • Solve Two Backtracking Array Problems - Meta (hard)
  • Solve Maze and Suffix Problems - Meta (medium)
Meta logo
Meta
Jan 21, 2026, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
9
0
Loading...

Maze shortest path

You are given a 2D grid maze of size m x n where:

  • 0 represents an open cell
  • 1 represents a wall (cannot pass)

You are also given a start cell (sr, sc) and a target cell (tr, tc).

From any open cell, you may move up, down, left, or right by 1 step (no diagonals), staying within bounds.

Task

Return the minimum number of steps required to reach the target from the start. If it is impossible, return -1.

Input/Output

  • Input: maze: int[][] , start: int[2] , target: int[2]
  • Output: int (minimum steps or -1 )

Assumptions / Constraints

  • 1 <= m, n <= 200
  • maze[sr][sc] == 0 and maze[tr][tc] == 0
  • The grid may be large enough that an efficient graph traversal is required.

Comments (0)

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 7,500+ 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.