Python 3 - 2 BFS clean code
For each push, make sure the person can stand at the required location that is reachable from a previous standing location.\n\npython\nclass Solution:\n    def 
For each push, make sure the person can stand at the required location that is reachable from a previous standing location.\n\n```python\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] == "T":\n                    target = (i,j)\n                if grid[i][j] == "B":\n                    box = (i,j)\n                if grid[i][j] == "S":\n                    person = (i,j)\n\n        def valid(x, y):\n            return 0<=x<m and 0<=y<n and grid[x][y]!=\'#\'\n        \n        def get_neighbor(i, j):\n            for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)]:\n                x, y = i + dx, j + dy\n                if valid(x, y):\n                    yield x, y\n        \n        def get_box_neighbor(i, j):\n            for dx,dy in [(-1,0),(0,-1)]:\n                x, y = i + dx, j + dy\n                px, py = i - dx, j - dy\n                if valid(x, y) and valid(px, py):\n                    yield (x, y), (px, py)\n                    yield (px, py), (x, y)\n\n        def check(curr, dest, box):\n            queue = deque([curr])\n            v = set()\n            while queue:\n                i, j = queue.popleft()\n                if (i, j) == dest: \n                    return True\n                for x, y in get_neighbor(i, j):\n                    if (x,y) not in v and (x,y) != box:\n                        v.add((x,y))\n                        queue.append((x,y))\n            return False\n\n        q = deque([(box, person)])\n        seen = set()\n        seen.add(box + person)\n        steps = 0\n        while q:\n            size = len(q)\n            for _ in range(size):\n                box, person = q.popleft()\n                if box == target:\n                    return steps\n                for new_box, new_person in get_box_neighbor(*box):\n                    if new_box + box not in seen and \\\n                            check(person, new_person, box):\n                        seen.add(new_box + box)\n                        q.append((new_box, box))\n            steps += 1\n        return -1\n```
[]