WHY TLE WITH DFS?? PLS HELP
Im counting all the possible path lengths and returning min of them\n```\nclass Solution:\n    def nearestExit(self, maze: List[List[str]], entrance: List[int])
Im counting all the possible path lengths and returning min of them\n```\nclass Solution:\n    def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n        n=len(maze)\n        m=len(maze[0])\n        ans=[]\n        def dfs(maze,i,j,c,visited):\n            \n            if [i,j]!=entrance and (i==0 or i==(n-1) or j==0 or j==(m-1)):\n                ans.append(c)\n                return \n            for x,y in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]:\n                if (x,y) not in visited and x>=0 and x<=(n-1) and y>=0 and y<=(m-1):\n                    if maze[x][y]==\'.\' :\n                        visited.add((x,y))\n                        dfs(maze,x,y,c+1,visited)\n                        visited.remove((x,y))\n            \n            \n        dfs(maze,entrance[0],entrance[1],0,set((entrance[0],entrance[1])))\n        return min(ans) if ans!=[] else -1\n
[]