✅ EZ Python || BFS
\nclass Solution:\n    def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n        """\n            . entrace cant be termed as exit cell
```\nclass Solution:\n    def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n        """\n            . entrace cant be termed as exit cell\n        """\n        \n        seen = set()\n        exits = set()\n        R, C = len(maze), len(maze[0])\n        entrance = tuple(entrance)\n        \n        for r in range(R):\n            if maze[r][0] == ".":\n                exits.add((r, 0))\n            if maze[r][C-1] == ".":\n                exits.add((r, C-1))\n        \n        for c in range(C):\n            if maze[0][c] == ".":\n                exits.add((0, c))\n            if maze[R-1][c] == ".":\n                exits.add((R-1, c))\n        \n        if entrance in exits:\n            exits.remove(entrance)\n        \n        \n        \n        q = [(entrance, 0)] # start, distance\n        \n        \n        while q:\n            curr_pos , d = q.pop(0)\n            \n            if curr_pos in exits:\n                return d\n            \n            if curr_pos in seen:\n                continue\n            \n            seen.add(curr_pos)\n            \n            \n            for dx, dy in [(0, 1), (0, -1), (1, 0), (-1, 0)]:\n                nx = dx + curr_pos[0]\n                ny = dy + curr_pos[1]\n                \n                if 0 <= nx < R and 0 <= ny < C and maze[nx][ny] == ".":\n                    q.append(((nx, ny), d + 1))\n            \n        \n        return -1\n```
['Python']