C++| BFS | O((m*n)^2)
This problem, is not too Hard. Just Think of brute force solution and apply BFS.\nWhat are the conditions to move from one cell to Another?\nLet\'s assume that 
This problem, is not too Hard. Just Think of brute force solution and apply BFS.\n**What are the conditions to move from one cell to Another?**\nLet\'s assume that current position of Box is **[i,j]**.\n* If We want to move box to [i+1,j] then this cell should\'nt contain any wall and player should be able to come to cell [i-1,j] from it\'s curr position.\n* If We want to move box to [i-1,j] then this cell should\'nt contain any wall and player should be able to come to cell [i+1,j] from it\'s curr position.\n* If We want to move box to [i,j+1] then this cell should\'nt contain any wall and player should be able to come to cell [i,j-1] from it\'s curr position.\n* If We want to move box to [i,j-1] then this cell should\'nt contain any wall and player should be able to come to cell [i,j+1] from it\'s curr position.\n\nChecking the Condition of player to move from one cell to another can be Done using BFS by applying the current position of Box and player. I have used BFS because of simpler implementation, you guys can use DSU also.\nUsing These extra conditions, apply simple BFS.\n```\nclass Solution {\npublic:\n    string stringigy(int x,int t,int a,int b){\n        return to_string(x)+"_"+to_string(t)+"_"+\n            to_string(a)+"_"+to_string(b);\n    }\n    bool check(vector<vector<char>>& nums,int ni,int nj,int i,int j,int x,int y){\n        vector<vector<bool>> vis(nums.size(),vector<bool>(nums[0].size(),0));\n        vis[i][j] = 1;\n        queue<pair<int,int>> q; \n        q.push({i,j});\n        while(!q.empty()){\n            int s = q.size();\n            while(s--){\n            auto [i,j] = q.front(); q.pop();\n            if(i==ni && j==nj) continue;\n            if(i==x && j==y) return 1;\n            if(i+1<nums.size() && !vis[i+1][j] && nums[i+1][j]!=\'#\' ){\n                q.push({i+1,j}); vis[i+1][j] = 1;\n            }\n            if(i-1>=0 && !vis[i-1][j] && nums[i-1][j]!=\'#\' ){\n                q.push({i-1,j}); vis[i-1][j] = 1;\n            }\n            if(j+1<nums[0].size() && !vis[i][j+1] && nums[i][j+1]!=\'#\' ){\n                q.push({i,j+1}); vis[i][j+1] = 1;\n            }\n            if(j-1>=0 && !vis[i][j-1] && nums[i][j-1]!=\'#\' ){\n                q.push({i,j-1}); vis[i][j-1] = 1;\n            }}\n        }\n        return 0;\n    }\n    int minPushBox(vector<vector<char>>& nums) {\n        int bi,bj,si,sj,ti,tj;\n        for(int i = 0; i<nums.size();++i){\n            for(int j = 0;j<nums[0].size();++j){\n                if(nums[i][j]==\'B\'){ bi = i,bj = j; }\n                if(nums[i][j]==\'S\'){ si = i,sj = j; }\n                if(nums[i][j]==\'T\'){ ti = i,tj = j; }\n            }\n        }\n        unordered_map<string,int> mp;\n        queue<vector<int>> q;\n        q.push({bi,bj,si,sj});\n        mp[stringigy(bi,bj,si,sj)]++;\n        int n = nums.size(),m=nums[0].size(),l=0;\n        while(!q.empty()){\n            int s = q.size();\n            while(s--){\n                vector<int> temp = q.front(); q.pop();\n                int i=temp[0],j=temp[1],si=temp[2],sj=temp[3];\n                if(i==ti && j==tj) return l;\n                if(j-1>=0 && nums[i][j-1]!=\'#\'){\n                   if(j+1<m && nums[i][j+1]!=\'#\' && mp.find(stringigy(i,j-1,i,j))==mp.end() &&\n                      check(nums,i,j,si,sj,i,j+1)){\n                       q.push({i,j-1,i,j});\n                       mp[stringigy(i,j-1,i,j)]++;\n                   }\n                }\n                if(j+1<m && nums[i][j+1]!=\'#\'){\n                    if(j-1>=0 && nums[i][j-1]!=\'#\' && mp.find(stringigy(i,j+1,i,j))==mp.end() &&\n                       check(nums,i,j,si,sj,i,j-1)){\n                        q.push({i,j+1,i,j});\n                        mp[stringigy(i,j+1,i,j)]++;\n                    }\n                }\n                if(i+1<n && nums[i+1][j]!=\'#\'){\n                    if(i-1>=0 && nums[i-1][j]!=\'#\' && mp.find(stringigy(i+1,j,i,j))==mp.end() &&\n                       check(nums,i,j,si,sj,i-1,j)){\n                        q.push({i+1,j,i,j});\n                        mp[stringigy(i+1,j,i,j)]++;\n                    }\n                }\n                if(i-1>=0 && nums[i-1][j]!=\'#\'){\n                     if(i+1<n && nums[i+1][j]!=\'#\' && mp.find(stringigy(i-1,j,i,j))==mp.end() &&\n                       check(nums,i,j,si,sj,i+1,j)){\n                         q.push({i-1,j,i,j});\n                         mp[stringigy(i-1,j,i,j)]++;\n                     }\n                }\n            }\n            l++;\n        }\n        return -1;\n    }\n};\n```\n
['Breadth-First Search', 'C']