PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Find shortest path in an OOP maze

Last updated: Mar 29, 2026

Quick Overview

This question evaluates graph traversal and shortest-path reasoning within an object-oriented codebase, focusing on state representation, neighbor exploration, visited-state management, and time/space complexity analysis.

  • medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Find shortest path in an OOP maze

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are working in a codebase that models a maze using object-oriented classes. The maze contains open cells and walls. You are given an entrance cell and an exit cell. Implement a function that returns the length of the shortest path from entrance to exit using 4-directional movement (up/down/left/right). If no path exists, return `-1`. ## Provided Interfaces (conceptual) Assume you are given objects with methods similar to: - `maze.get_entrance() -> Cell` - `maze.get_exit() -> Cell` - `maze.get_neighbors(cell: Cell) -> List[Cell]` Returns adjacent cells you can move to (already excludes walls/out-of-bounds). - `cell.id` (or any stable identity / coordinates) You may assume `Cell` objects can be used to identify visited states (via `id`, coordinates, or hashing). ## Input - A `Maze` object as described. ## Output - Integer shortest distance (number of moves) from entrance to exit, or `-1`. ## Constraints - Maze can be large; your solution should be `O(V+E)` where `V` is number of reachable cells. ## Example If the shortest route requires 7 moves, return `7`.

Quick Answer: This question evaluates graph traversal and shortest-path reasoning within an object-oriented codebase, focusing on state representation, neighbor exploration, visited-state management, and time/space complexity analysis.

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
Software Engineer
Onsite
Coding & Algorithms
1
0
Loading...

You are working in a codebase that models a maze using object-oriented classes. The maze contains open cells and walls. You are given an entrance cell and an exit cell.

Implement a function that returns the length of the shortest path from entrance to exit using 4-directional movement (up/down/left/right). If no path exists, return -1.

Provided Interfaces (conceptual)

Assume you are given objects with methods similar to:

  • maze.get_entrance() -> Cell
  • maze.get_exit() -> Cell
  • maze.get_neighbors(cell: Cell) -> List[Cell]
    Returns adjacent cells you can move to (already excludes walls/out-of-bounds).
  • cell.id (or any stable identity / coordinates)

You may assume Cell objects can be used to identify visited states (via id, coordinates, or hashing).

Input

  • A Maze object as described.

Output

  • Integer shortest distance (number of moves) from entrance to exit, or -1 .

Constraints

  • Maze can be large; your solution should be O(V+E) where V is number of reachable cells.

Example

If the shortest route requires 7 moves, return 7.

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.