simple & easy BFS solution
Code\nPython [0]\nclass Solution:\n    def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n        n, m = len(maze), len(maze[0])\n      
# Code\n``` Python [0]\nclass Solution:\n    def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n        n, m = len(maze), len(maze[0])\n        \n        q = []\n        q.append([entrance[0], entrance[1]])\n        \n        ans = 0\n        while q:\n            temp = q.copy()\n            q.clear()\n            size = len(temp)\n\n            for curr in temp:\n                i, j = curr\n                \n                if ans > 0 and (i + 1 == n or i - 1 == -1 or j + 1 == m or j - 1 == -1):\n                    return ans\n                if i + 1 < n and maze[i + 1][j] == \'.\':\n                    q.append([i + 1, j])\n                    maze[i + 1][j] = \'+\'\n                if i - 1 >= 0 and maze[i - 1][j] == \'.\':\n                    q.append([i - 1, j])\n                    maze[i - 1][j] = \'+\'\n                if j + 1 < m and maze[i][j + 1] == \'.\':\n                    q.append([i, j + 1])\n                    maze[i][j + 1] = \'+\'\n                if j - 1 >= 0 and maze[i][j - 1] == \'.\':\n                    q.append([i, j - 1])\n                    maze[i][j - 1] = \'+\'\n                maze[i][j] = \'+\'\n            ans += 1\n        return -1\n\n\n```
['Array', 'Breadth-First Search', 'Matrix', 'Python3']