Python [for newbie] BFS,  borrowed from @davyjing
I cleaned a bit the excellent code of @davyjing for new comers. \n\nclass Solution:\n    def minPushBox(self, grid: List[List[str]]) -> int:\n        m, n = len
I cleaned a bit the excellent code of @davyjing for new comers. \n```\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] == \'B\': box = (i, j)\n                if grid[i][j] == \'T\': target = (i, j)\n                if grid[i][j] == \'S\': player = (i, j)\n                    \n        if target == box: return 0\n        \n        def can_get(cur_b, cur_p, pos): # can player get to a certain position pos\n            if cur_p == pos: return True\n            seen = {cur_p}\n            q = [cur_p]\n            for x, y in q:\n                for X, Y in ([(x-1, y), (x+1, y), (x, y-1), (x, y+1)]):\n                    if 0 <= X < m and 0 <= Y < n and (X, Y) not in seen and grid[X][Y] != \'#\' and (X, Y) != cur_b:\n                        if (X, Y) == pos:\n                            return True\n                        seen.add((X, Y))\n                        q.append((X, Y))\n            return False\n        \n        q, seen, ans = {(box, player)}, {(box, player)}, 0\n        dire = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n        while q:\n            tmp = []\n            ans += 1\n            for b, p in q:\n                for d in dire:\n                    nb = (b[0] + d[0], b[1] + d[1])\n                    oppo = (b[0] - d[0], b[1] - d[1]) # player is required to be the opposite side of the box to push\n                    if 0 <= nb[0] < m and 0 <= nb[1] < n and grid[nb[0]][nb[1]] != \'#\' and can_get(b, p, oppo) and (nb, b) not in seen:\n                        tmp.append((nb, b))\n            q = set(tmp)\n            seen |= q\n            for d in dire:\n                if (target, (target[0]+d[0], target[1]+d[1])) in seen:\n                    return ans\n                    \n        return -1\n```
[]