😃 Python BFS Easy with comments
We perform a breadth-first search of the maze, using a queue.\n\n\nclass Solution:\n    def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int
We perform a breadth-first search of the maze, using a queue.\n\n```\nclass Solution:\n    def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n        # BFS \n        rows, cols = len(maze), len(maze[0])\n        \n        # Set visited spaces to "+"\n        maze[entrance[0]][entrance[1]] = \'+\'\n        \n        # Process stops in a queue\n        queue = collections.deque()\n        # Add first stop in queue\n        queue.appendleft([entrance[0],entrance[1],0])\n    \n        # Iterate until queue empty or we reach an exit\n        while queue:\n            row, col, steps = queue.pop()\n    \n            # Check each direction breadth first\n            for r, c in [[row+1, col], [row-1, col], [row, col+1], [row, col-1]]:\n                # Check in bounds and it not a wall\n                if 0 <= r < rows and 0 <= c < cols and maze[r][c] == \'.\':\n                    # Check for exit\n                    if (r == 0) or (c == 0) or (r == rows - 1) or (c == cols -1):\n                        return steps+1\n                    # Add stop to visited \n                    maze[r][c] = \'+\'\n                    # BFS, new stops get added at the end of the queue, not the front\n                    queue.appendleft([r,c,steps+1])\n        # No exit found\n        return -1\n```\n            \n**Please upvote if you found this solution helpful!**\n        \n
['Breadth-First Search', 'Queue', 'Python', 'Python3']