PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches

Quick Overview

This question evaluates competency in grid-based pathfinding, graph modeling, and algorithmic complexity analysis for computing shortest paths in discrete spaces.

  • hard
  • Airbnb
  • Coding & Algorithms
  • Software Engineer

Compute maze score using shortest path

Company: Airbnb

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

You are given a grid-based maze game. - The maze is an `R x C` grid of characters: - `'#'` = wall (cannot pass) - `'.'` = empty cell - `'S'` = current player position (exactly one) - `'E'` = exit/goal (exactly one) - The game “score” for a state is defined as the length of the shortest path (minimum number of moves) from `S` to `E`, moving 4-directionally (up/down/left/right) and not passing through walls. - If `E` is unreachable, return `-1`. Write a function that takes the maze grid and returns the score. Clarify in your solution: - Time and space complexity - How you would adapt it if the game state were provided separately as `(startRow, startCol)` instead of embedding `'S'` in the grid.

Quick Answer: This question evaluates competency in grid-based pathfinding, graph modeling, and algorithmic complexity analysis for computing shortest paths in discrete spaces.

You are given a grid-based maze game represented as a list of strings. Each cell contains one of the following characters: '#' for a wall, '.' for an empty cell, 'S' for the player's current position, and 'E' for the exit. The maze score is defined as the length of the shortest path from 'S' to 'E', moving only up, down, left, or right, and never passing through walls. If the exit cannot be reached, return -1.

Constraints

  • 1 <= R, C <= 200
  • All rows have the same length
  • There is exactly one 'S' and exactly one 'E'
  • Movement is allowed only in 4 directions: up, down, left, right

Examples

Input: (['S..', '.#.', '..E'],)

Expected Output: 4

Explanation: A shortest path is right, right, down, down for a total of 4 moves.

Input: (['S#.', '###', '.E.'],)

Expected Output: -1

Explanation: Walls block every possible route from S to E.

Input: (['SE'],)

Expected Output: 1

Explanation: The exit is directly adjacent to the start in a single-row maze.

Input: (['..#E', '.#..', 'S...'],)

Expected Output: 5

Explanation: One shortest path is (2,0)->(2,1)->(2,2)->(2,3)->(1,3)->(0,3), which uses 5 moves.

Input: (['S', '.', '.', 'E'],)

Expected Output: 3

Explanation: In this single-column maze, you move down 3 times to reach the exit.

Hints

  1. This is an unweighted shortest-path problem on a grid, so consider breadth-first search.
  2. Once you visit a cell for the first time in BFS, you have already found the shortest path to it.
Last updated: Apr 19, 2026

Loading coding console...

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.

Related Coding Questions

  • Determine Exact Layover Booking - Airbnb (medium)
  • Solve Linked-List and Iterator Problems - Airbnb
  • Implement Text Layout and Query Parsing - Airbnb (easy)
  • Parse Query Parameters Into a Map - Airbnb (medium)
  • Find smallest permutation under constraints - Airbnb (medium)