Given a maze of open cells and walls, return the minimum number of steps required to reach any exit from a given entrance cell. An exit is any open border cell other than the entrance. Pattern focus: BFS shortest path. Expand level by level so the first border cell reached is the answer.
maze = character grid, entrance = [row, col]
minimum steps to the nearest exit, or -1
Example 1:
Input:
maze = [["+","+","."],[".",".","."],["+","+","+"]] entrance = [1,0]
Output:
2
Explanation:
The exit at the right side is the closest reachable border cell.
Example 2:
Input:
maze = [[".","."]] entrance = [0,0]
Output:
1
Explanation:
The other border cell is a valid exit.
Example 3:
Input:
maze = [["+",".","+"],[".",".","."],["+","+","+"]] entrance = [1,1]
Output:
1
Explanation:
A border exit is one step away.