Two BFS for player and box - beats 100 %
\npublic class Solution \n{\n    private int[] x = new int[4] { 0, 0, 1, -1 };\n    private int[] y = new int[4] { 1, -1, 0, 0 };\n    \n    public int MinPushB
```\npublic class Solution \n{\n    private int[] x = new int[4] { 0, 0, 1, -1 };\n    private int[] y = new int[4] { 1, -1, 0, 0 };\n    \n    public int MinPushBox(char[][] grid) \n    {\n        int bx = 0, by = 0, px = 0, py = 0, tx = 0, ty = 0;\n        \n        int m = grid.Length;\n        int n = grid[0].Length;\n        \n        // Set to maintain the visited positions of the player and box\n        HashSet<int> boxSet = new HashSet<int>();\n        HashSet<int> playerSet = new HashSet<int>();\n        \n        for(int i = 0; i < m; i++)\n        {\n            for(int j = 0; j < n; j++)\n            {\n                if(grid[i][j] == \'B\')\n                {\n                    bx = i;\n                    by = j;\n                }\n                else if(grid[i][j] == \'S\')\n                {\n                    px = i;\n                    py = j;\n                }\n                else if(grid[i][j] == \'T\')\n                {\n                    tx = i;\n                    ty = j;\n                }\n            }\n        }\n        \n        Queue<Position> queue = new Queue<Position>();\n        \n        Position pos = new Position(px, py, bx, by);\n        \n        queue.Enqueue(pos);\n        \n        boxSet.Add(bx * n + by);\n        \n        for(int step = 0; queue.Count > 0; step++)\n        {\n            for(int size = queue.Count; size > 0; size--)\n            {\n                pos = queue.Dequeue();\n            \n                // Box has reached the target location\n                if(pos.bx == tx && pos.by == ty)\n                    return step;\n                \n                for(int i = 0; i < 4; i++)\n                {\n                    // Compute box position\n                    bx = pos.bx + x[i];\n                    by = pos.by + y[i];\n                    \n                    // Compute player position to move the box\n                    px = pos.bx - x[i];\n                    py = pos.by - y[i];\n                    \n                    if(bx < 0 || bx > m - 1 || by < 0 || by > n - 1)\n                        continue;\n                    \n                    if(px < 0 || px > m - 1 || py < 0 || py > n - 1)\n                        continue;\n                    \n                    if(grid[px][py] != \'#\' && grid[bx][by] != \'#\'  && (boxSet.Add(bx * n + by) || playerSet.Add(px * n + py)) && CanReachThePosition(grid, pos.px, pos.py, px, py, pos.bx, pos.by, m, n))\n                    {\n                        queue.Enqueue(new Position(pos.bx, pos.by, bx, by));\n                    }\n                }\n            }\n        }\n        \n        return -1;\n    }\n    \n    // Check whether the player can reach the required position to move the box in a particular direction\n    private bool CanReachThePosition(char[][] grid, int x1, int y1, int x2, int y2, int bx, int by, int m, int n)\n    {\n        Queue<Position> queue = new Queue<Position>();\n        queue.Enqueue(new Position(x1, y1, x2, y2));\n        \n        HashSet<int> set = new HashSet<int>();\n        \n        set.Add(x1 * n + y1);\n        set.Add(bx * n + by);\n        \n        while(queue.Count > 0)\n        {\n            Position pos = queue.Dequeue();\n            \n            if(pos.px == x2 && pos.py == y2)\n                return true;\n\n            for(int i = 0; i < 4; i++)\n            {\n                int px = pos.px + x[i];\n                int py = pos.py + y[i];\n\n                if(px < 0 || px > m - 1 || py < 0 || py > n - 1)\n                    continue;\n                \n                if(grid[px][py] != \'#\' && set.Add(px * n + py))\n                {\n                    queue.Enqueue(new Position(px, py, x2, y2));\n                }\n            }\n        }\n        \n        return false;\n    }\n}\n\npublic class Position\n{\n    // Player\'s position in the grid\n    public int px;\n    public int py;\n    \n    // Box position in the grid\n    public int bx;\n    public int by;\n    \n    public Position(int px, int py, int bx, int by)\n    {\n        this.px = px;\n        this.py = py;\n        this.bx = bx;\n        this.by = by;\n    }\n}\n```
[]