Simple Python BFS Solution
Intuition\nStart from the entrance, do BFS and expand the search, if we are out of the maze, return the distance travelled\n\n# Approach\n- start from the entra
# Intuition\nStart from the entrance, do BFS and expand the search, if we are out of the maze, return the distance travelled\n\n# Approach\n- start from the entrance of maze\n- expand the search using BFS updating the distance travelled for every cell\n- if we are out of the maze, then return the current distance\n\n# Complexity\n- Time complexity:\nO(m * n) where m and n are the number of rows and columns\n\n- Space complexity:\nsince we used a set to store visited cells, space complexity is O(m * n) where m and n are the number of rows and columns\n\n# Code\n```\nclass Solution:\n    def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n        queue = deque([(entrance[0], entrance[1], 0)])\n        visited = set()\n        visited.add((entrance[0], entrance[1]))\n        m = len(maze)\n        n = len(maze[0])\n        while queue:\n            x, y, d = queue.popleft()\n            for i, j in [(x, y - 1), (x - 1, y), (x + 1, y), (x, y + 1)]:\n                if 0 <= i < m and 0 <= j < n:\n                    if (i, j) not in visited and maze[i][j] == ".":\n                        queue.append((i, j, d + 1))\n                        visited.add((i, j))\n                elif (x, y) != (entrance[0], entrance[1]):\n                    return d\n        return -1\n```
['Breadth-First Search', 'Python3']