Nearest Exit from Entrance in Maze
Medium · Queue & Deque · about 15 minutes
Asked at Amazon, Meta, Uber, eBay, PayPal, Visa, Wayfair, Chime, Affirm, American Express, Shopee, Zalando.
A maze is an m × n grid of '.' (empty) and '+' (wall), given as strings. Starting at entrance = [r, c], move up, down, left or right through empty cells. An exit is an empty cell on the border, other than the entrance. Return the number of steps to the nearest exit, or -1 if there is none.