Python BFS
\nclass Solution:\n    def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n        ex,ey = entrance\n        rows = len(maze)\n        co
```\nclass Solution:\n    def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n        ex,ey = entrance\n        rows = len(maze)\n        cols = len(maze[0])\n        \n        def onBorder(r,c):   #check if cell is on the border and not the entrance cell\n            if (r in [0,rows-1] or c in [0,cols-1]) and (r,c)!=(ex,ey):\n                return True\n            return False\n        \n        def isnotwall(r,c): # check if cell is a wall\n            if 0<=r<rows and 0<=c<cols and maze[r][c]==\'.\':\n                return True\n            return False\n        \n        maze[ex][ey] = \'+\'\n        queue = [(ex,ey,0)]\n        while queue:\n            r,c,steps = queue.pop(0)\n            if onBorder(r,c):\n                return steps\n            for r1,c1 in [(0,1),(0,-1),(1,0),(-1,0)]:\n                if isnotwall(r1+r, c1+c):\n                    maze[r1+r][c1+c] = \'+\'  # marking a cell as wall bc we dont want to visit again\n                    queue.append((r1+r, c1+c,steps+1))\n            \n        return -1\n```
[]