Python BFS solution- beats 96% in time and 91% in space
Intuition\nThis problem can be solved using the Breadth-first search since the minimum number of steps has to be found from a start point. \n\n# Approach\n1. In
# Intuition\nThis problem can be solved using the Breadth-first search since the minimum number of steps has to be found from a start point. \n\n# Approach\n1. Initialize a queue with in which each entry is a list of 3 elements- [x, y, distance/steps so far].\n2. Append the entrance point with steps 0 to the queue.\n3. In every iteration, pop the leftmost element of queue, find all the points x1,y1 adjacent to the element marked with \'.\'.\n4. If it a border element, return the distance.\n5. Else, append it to the queue with the entry [x1, y1, distance+1].\n\n# Complexity\n- Time complexity:\nO(m*n)\n\n- Space complexity:\nO(m*n)\n\n# Code\n```\nclass Solution(object):\n    def nearestExit(self, maze, entrance):\n        """\n        :type maze: List[List[str]]\n        :type entrance: List[int]\n        :rtype: int\n        """\n        m=len(maze)\n        n=len(maze[0])\n        directions=[(-1,0),(1,0),(0,-1),(0,1)]\n        queue=deque()\n        queue.append([entrance[0],entrance[1],0])\n        maze[entrance[0]][entrance[1]] = \'+\'\n        while queue:\n            elex,eley,dist=queue.popleft()\n            for x,y in directions:\n                x1=elex+x\n                y1=eley+y\n                if 0<=x1<=m-1 and 0<=y1<=n-1 and maze[x1][y1]==\'.\':\n                    if x1==0 or x1==m-1 or y1==0 or y1==n-1:\n                        return dist+1\n                    else:\n                        maze[x1][y1] = \'+\'\n                        queue.append([x1,y1,dist+1])\n        return -1\n\n\n```
['Python']