As reported: PayPal Staff Engineer Full Stack, DSA round on graphs (2025): find the nearest exit in a maze grid — BFS from the entry, detecting the edge of the grid, tracking visited cells.
maze is an m × n grid of '.' (open) and '+' (wall). You stand at entrance = [row, col], an open cell. Each step moves up, down, left or right into an open cell. An exit is an open cell on the border of the maze; the entrance itself does not count as an exit. Return the number of steps on the shortest path to the nearest exit, or -1 if none is reachable.
This is LeetCode 1926 — Nearest Exit from Entrance in Maze.
Example 1
maze = [["+","+",".","+"],
[".",".",".","+"],
["+","+","+","."]], entrance = [1,2] -> 1
Example 2
maze = [["+","+","+"],
[".",".","."],
["+","+","+"]], entrance = [1,0] -> 2
The entrance is on the border but is not an exit; the nearest exit is [1,2].
Example 3
maze = [[".","+"]], entrance = [0,0] -> -1
Constraints: 1 ≤ m, n ≤ 100; maze[i][j] is '.' or '+'; the entrance is an open cell.
Code runner format: one JSON value per line: maze, then entrance. Implement nearestExit(maze, entrance); the harness prints the step count.