Compute maze score using shortest path
Company: Airbnb
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Quick Answer: This question evaluates competency in grid-based pathfinding, graph modeling, and algorithmic complexity analysis for computing shortest paths in discrete spaces.
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.