Single BFS || Priority queue || Intuitive Solution
\n\nclass Solution {\npublic:\n\nint dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};\nint dp[22][22][22][22],vis[22][22][22][22];\nint ti,tj;\nbool check(int i,int j,ve
\n```\nclass Solution {\npublic:\n\nint dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};\nint dp[22][22][22][22],vis[22][22][22][22];\nint ti,tj;\nbool check(int i,int j,vector<vector<char>>& grid){\n     int n=grid.size(),m=grid[0].size();\n    if(i<0 || i>=n ||j<0|| j>=m || grid[i][j]==\'#\') return false;\n    return true;\n}\n\n    int minPushBox(vector<vector<char>>& grid) {\n        int si,sj,bi,bj;\n        int n=grid.size(),m=grid[0].size();\n        memset(dp,-1,sizeof(dp));\n         memset(vis,0,sizeof(vis));\n        for(int i=0;i<n;i++)\n            for(int j=0;j<m;j++){\n              if(grid[i][j] == \'S\')\n                si=i,sj=j;\n              if(grid[i][j] == \'B\')\n              bi=i,bj=j;\n              if(grid[i][j] == \'T\')\n              ti=i,tj=j;\n                }\n        \nint ans = 0;\n\n\n\npriority_queue<vector<int>> q;\nq.push({0,si,sj,bi,bj});\nvis[si][sj][bi][bj] = 1;\n\nwhile(!q.empty()){\n    int sz = q.size();\n    while(sz--){\n        auto p = q.top(); q.pop();\n        int d=p[0];\n        si = p[1], sj=p[2],bi=p[3],bj=p[4];\n\n        if(bi==ti && bj==tj) return -d;\n\n        for(int i=0;i<4;i++){\n       int x = si + dx[i], y=sj+dy[i];\n\n       if(check(x,y,grid) && (!(x==bi && y==bj) || check(x+dx[i],y+dy[i],grid))){\n        if(x==bi && y==bj){\n          if(vis[x][y][dx[i]+x][dy[i]+y] == 0)\n           q.push({d-1,x,y,dx[i]+x,dy[i]+y});\n           vis[x][y][dx[i]+x][dy[i]+y]=1;\n         }\n         else{\n           if(vis[x][y][bi][bj] == 0)\n        q.push({d,x,y,bi,bj});\n        vis[x][y][bi][bj]=1;\n        }\n       }\n   }\n    }\n\n    ans++;\n}\nreturn -1;\n\n    }\n};\n```
['C++']