Python - Very Upset. Finish 20 seconds after the contest end!
\nclass Solution:\n    def minPushBox(self, grid: List[List[str]]) -> int:\n        m, n = len(grid), len(grid[0])\n        for i in range(m):\n            for 
```\nclass Solution:\n    def minPushBox(self, grid: List[List[str]]) -> int:\n        m, n = len(grid), len(grid[0])\n        for i in range(m):\n            for j in range(n):\n                if grid[i][j] == "S":\n                    people = [i, j]\n                if grid[i][j] == "T":\n                    end = [i, j]\n                if grid[i][j] == "B":\n                    box = [i, j]\n        if box == end: return 0\n        dict1 = collections.defaultdict(int)\n        dict1[tuple(box)] = 1\n        queue = collections.deque()\n        queue.append(box + [0] + people)\n        cnt = 0\n        while queue:\n            x, y, step, nx, ny = queue.pop()\n            if [x, y] == end:\n                return step\n            neighs = [[x+1, y, x-1, y], [x-1, y, x+1, y], [x, y-1, x, y+1], [x, y+1,x, y-1]]\n            for dx, dy, sx, sy in neighs:\n                if 0 <= dx < m and 0 <= dy < n:\n                    if dict1[(dx, dy)] < 4 and grid[dx][dy] != "#":\n                        if 0 <= sx < m and 0 <= sy < n and grid[sx][sy] != "#":\n                            if [sx, sy] == [x,y] or self.dfs([sx, sy], [nx, ny], grid, [x, y], set([(sx, sy)])):\n                                dict1[(dx, dy)] += 1\n                                queue.appendleft([dx, dy, step+1, x, y])\n            cnt += 1\n        return -1\n    \n    def dfs(self, start, end, grid, box, visited):\n        m, n = len(grid), len(grid[0])\n        if start == end: return True\n        i, j = start\n        neighs = [[i+1, j], [i-1, j], [i, j-1], [i, j+1]]\n        tmp = False\n        for di, dj in neighs:\n            if 0 <= di < m and 0 <= dj < n:\n                if grid[di][dj] != "#" and (di, dj) not in visited and [di, dj] != box:\n                    visited.add((di, dj))\n                    tmp = tmp or self.dfs([di, dj], end, grid, box, visited)\n                    if tmp:\n                        break\n        return tmp\n            \n```
[]