Beats 100% users
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def minPushBox(self, grid: List[List[str]]) -> int:\n        m = len(grid)\n        n = len(grid[0])\n\n        def neighbours(x,y):\n            res = []\n            cand = [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]\n            for e in cand:\n                x_cand,y_cand = e\n                if 0 <= x_cand < n and 0 <= y_cand < m and grid[y_cand][x_cand] != "#":\n                    res.append(e)\n            return(res)\n\n        def find(car):\n            for x in range(n):\n                for y in range(m):\n                    if grid[y][x] == car:\n                        return(x,y)\n\n        def oppose(neighbour,boite):\n            nx,ny = neighbour\n            bx,by = boite\n            candx,candy = 2*bx-nx,2*by-ny\n            return(candx,candy)\n\n        def is_accessible(P,O,B):\n            visited = set()\n            to_visit = [P]\n            while to_visit:\n                current_P = to_visit.pop(0)\n                if current_P == O:\n                    return(True)\n                if not current_P in visited:\n                    visited.add(current_P)\n                    px,py = current_P\n                    neighs = neighbours(px,py)\n                    for neigh in neighs:\n                        if neigh != B:\n                            to_visit.append(neigh)\n\n            return(False)\n\n        P = find(\'S\')\n        B = find(\'B\')\n\n        seen_set = set()\n        seen_set.add((P,B))\n\n        state_stack = [(P,B,0)]\n        while state_stack:\n            P,B,count = state_stack.pop(0)\n            bx,by = B\n            if grid[by][bx] == \'T\':\n                return(count)\n            neighs = neighbours(bx,by)\n            for neigh in neighs:\n                if (B,neigh) not in seen_set: # nouvel etat\n                    oppx,oppy = oppose(neigh,B)\n                    O = oppx,oppy \n                    if 0 <= oppx < n and 0 <= oppy < m and grid[oppy][oppx] != "#":\n                        if is_accessible(P,O,B):\n                            seen_set.add((B,neigh))\n                            state_stack.append((B,neigh,count+1))\n        return(-1)\n![4.png](https://assets.leetcode.com/users/images/eca300c7-0903-492a-9700-ee45d24864da_1710169202.8649113.png)\n\n\n\n        \n```
['Python', 'Python3']