Python3 | Modified BFS and Heap
Complexity\n- Time complexity: O(m^2 \cdot n^2 \cdot \log(m^2 \cdot n^2))\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(m^2 \cdot n^2)\n 
# Complexity\n- Time complexity: $$O(m^2 \\cdot n^2 \\cdot \\log(m^2 \\cdot n^2))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(m^2 \\cdot n^2)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nimport heapq\n\nclass Solution:\n    def minPushBox(self, grid: List[List[str]]) -> int:\n        table = set()\n        p = b = target = None\n        for i, line in enumerate(grid):\n            for j, elem in enumerate(line):\n                if elem == \'#\':\n                    continue\n                table.add((i, j))\n                if elem == \'S\':  # player\n                    p = (i, j)\n                elif elem == \'B\':  # box\n                    b = (i, j)\n                elif elem == \'T\':  # target\n                    target = (i, j)\n        \n        h = [(0, p, b)]\n        in_progress = set()\n\n        while h:\n            dist, p, b = heapq.heappop(h)\n            if (p, b) in in_progress:\n                continue\n            in_progress.add((p, b))\n\n            if b == target:\n                return dist\n            \n            dx = b[0] - p[0]\n            dy = b[1] - p[1]\n            if (\n                (abs(dx) == 1 and dy == 0)\n                or (abs(dy) == 1 and dx == 0)\n            ):\n                new_b = (b[0] + dx, b[1] + dy)\n                if new_b in table:\n                    heapq.heappush(h, (dist + 1, b, new_b))\n            \n            for dx, dy in ((-1, 0), (1, 0), (0, -1), (0, 1)):\n                new_p = (p[0] + dx, p[1] + dy)\n                if new_p in table and new_p != b:\n                    heapq.heappush(h, (dist, new_p, b))\n        \n        return -1\n```
['Breadth-First Search', 'Heap (Priority Queue)', 'Matrix', 'Python3']