fastest solution, beats 100% with an old school trick
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n- I modify maze to mark visited cells\n- I use "loop unrolling" technique
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n- I modify maze to mark visited cells\n- I use "loop unrolling" technique to look up, down, left, right\n\n\n# Complexity\n- Time complexity:\nBeats 100%\n\n\n- Space complexity:\nBeats 66.3%\n\n# Code\n```\nclass Solution:\n    def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n        len_y = len(maze)-1\n        len_x = len(maze[0])-1\n\n        if len_x==0 and len_y==0:\n                return -1\n\n        queue = collections.deque()\n\n\n        queue.append((entrance[0],entrance[1]))\n\n        maze[entrance[0]][entrance[1]] = 2\n        moves=0\n        while queue:\n\n                for i in range(len(queue)):\n                        current_y, current_x = queue.popleft()\n\n\n                        if not (current_x== entrance[1] and current_y== entrance[0]) and (current_y==0 or current_y == len_y or current_x== 0 or current_x ==len_x):\n                                return moves\n\n\n                        #up\n                        if current_y-1>=0 and maze[current_y - 1][current_x] == \'.\':\n                                queue.append((current_y-1,current_x))\n                                maze[current_y-1][current_x]=2\n                        # down\n                        if current_y+1 <= len_y and maze[current_y + 1][current_x] == \'.\':\n                                queue.append((current_y + 1, current_x))\n                                maze[current_y+1][current_x] = 2\n                        #left\n                        if current_x-1 >=0 and maze[current_y][current_x-1] == \'.\':\n                                queue.append((current_y, current_x-1))\n                                maze[current_y][current_x-1] = 2\n                        #right\n                        if current_x+1 <=len_x and maze[current_y][current_x+1] == \'.\':\n                                queue.append((current_y, current_x+1))\n                                maze[current_y][current_x+1] = 2\n\n\n                moves+=1\n\n        return -1\n```
['Python3']