Python BFS solution
\nclass Solution:\n    def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n        m, n = len(maze), len(maze[0])\n        node = tuple(e
```\nclass Solution:\n    def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n        m, n = len(maze), len(maze[0])\n        node = tuple(entrance)\n        q = deque([node])\n        level = 0\n        visited = set([node])\n        while q:\n            for _ in range(len(q)):\n                i, j = q.popleft()\n                if (i != entrance[0] or j != entrance[1]) and (i == 0 or j == 0 or i == m - 1 or j == n - 1):\n                    return level\n                for x, y in [(i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)]:\n                    if 0 <= x < m and 0 <= y < n and maze[x][y] == \'.\' and (x, y) not in visited:\n                        q.append((x, y))\n                        visited.add((x, y))\n            level += 1\n        return -1\n```
['Breadth-First Search', 'Python']