Python3 BFS with comments
Idea: use BFS to return shortest path. Since we start BFS from the entrance and iterate level by level, one of our chosen paths will be the minimum (if it exist
Idea: use BFS to return shortest path. Since we start BFS from the entrance and iterate level by level, one of our chosen paths will be the minimum (if it exists)\n```\ndef nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n        dirs = [(0,1),(0,-1),(1,0),(-1,0)]\n        entrance = (entrance[0],entrance[1])\n        q = deque([entrance])\n        visited = set()\n        visited.add(entrance)\n        step = 0\n        while q:\n            stepLength = len(q)\n            for i in range(stepLength): # here, we can use length of the deque to iterate through level by level\n                node = q.popleft()\n                if node[0] == 0 or node[0] == len(maze) -1 or node[1] == 0 or node[1] == len(maze[0]) -1 :\n                    if maze[node[0]][node[1]] == \'.\' and (node[0],node[1]) != entrance:\n                        return step\n                for d in dirs:\n                    newD = (node[0] + d[0], node[1] + d[1])\n                    if newD not in visited and 0<=newD[0]<len(maze) and 0<=newD[1]<len(maze[0]) and maze[newD[0]][newD[1]] == \'.\': # only add valid nodes to the queue!\n                        visited.add(newD) # mark it as visited, so we don\'t loop forever\n                        q.append(newD)\n            step += 1 # after we finish with a level, increment step by one\n        return -1\n\n```
['Breadth-First Search', 'Python', 'Python3']