Python Straightforward 2-stage BFS, Explained
First define a function to check from current state, what are the possible neighbouring states (use BFS to check if we can move the player to required location)
First define a function to check from current state, what are the possible neighbouring states (use BFS to check if we can move the player to required location). Notice that the state includes both the location of the box and the player.\nSecond BFS to see if we can reach the target location.\n```\nclass Solution:\n    def minPushBox(self, grid: List[List[str]]) -> int:\n        dire = [(1,0),(0,1),(-1,0),(0,-1)]\n\t\t\n        def can_get(cur_b,cur_p,tar):\n            seen,cur = set([cur_p]),set([cur_p])\n            while cur:\n                tmp = []\n                for loc in cur:\n                    for x,y in dire:\n                        if 0<= loc[0]+x < len(grid) and 0 <= loc[1] + y < len(grid[0]) and (loc[0]+x,loc[1] +y) != cur_b and grid[loc[0] +x][loc[1] +y] != \'#\' and (loc[0]+x,loc[1] +y) not in seen:\n                            tmp += [(loc[0]+x,loc[1] +y)]\n                cur = set(tmp)\n                seen |= cur\n                if tar in seen:\n                    return True\n            return False\n\t\t\t\n        for i in range(len(grid)):\n            for j in range(len(grid[0])):\n                if grid[i][j] == \'B\': box = (i,j)\n                if grid[i][j] == \'S\': player = (i,j)\n                if grid[i][j] == \'T\': target = (i,j)\n\t\t\t\t\n        seen,cur,res = set([(box,player)]), set([(box,player)]), 0\n        while cur:\n            tmp = []\n            res += 1\n            for b,p in cur:\n                for x,y in dire:\n                    if 0<= b[0]+x < len(grid) and 0 <= b[1] + y < len(grid[0]) and grid[b[0]+x][b[1]+y] != \'#\' and can_get(b,p,(b[0]-x,b[1]-y)) and ((b[0]+x,b[1]+y),b) not in seen:\n                        tmp += [((b[0]+x,b[1]+y),b)]\n            cur = set(tmp)\n            seen |= cur\n            for x,y in dire:\n                if (target,(target[0]+x,target[1]+y)) in seen:\n                    return res\n        return -1\n```
[]