Easy Brute Force DFS✅✅
Approach\n Describe your approach to solving the problem. \n- We just need to push all the stones to the right if they can.\n- So we iterate from the last col a
# Approach\n<!-- Describe your approach to solving the problem. -->\n- We just need to push all the stones to the right if they can.\n- So we iterate from the last col and through each row.\n- Whenever we get a stone we can see how far to the right we can push it, and then place it at that position.\n# Complexity\n- Time complexity: $$O(n\\cdot m)$$ \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n\\cdot m)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<vector<char>> rotateTheBox(vector<vector<char>>& box) {\n        int n = box.size();\n        int m = box[0].size();\n        for(int c=m-1; c>=0; c--){\n            for(int r=0; r<n; r++){\n                if(box[r][c] == \'#\'){\n                    //it\'s stone\n                    int col = c;\n                    if(col!=m-1){\n                        // col++;\n                        while(col<m-1 && box[r][col+1] == \'.\'){\n                            col++;\n                        }\n                        box[r][c] = \'.\';\n                        box[r][col] = \'#\';\n                    }\n                }\n            }\n        }\n        // for(int i=0; i<n; i++) {\n        //     for(int j=0; j<m; j++){\n        //         cout<<box[i][j]<<" ";\n        //     }cout<<endl;\n        // }\n\n        //placing the elements in the rotated array\n        vector<vector<char>> ans;\n        for(int c=0; c<m; c++){\n            vector<char> temp;\n            for(int r=0; r<n; r++){\n                temp.push_back(box[r][c]);\n            }\n            reverse(temp.begin(), temp.end());\n            ans.push_back(temp);\n        }\n        return ans;\n    }\n};\n```\n```java []\nclass Solution {\n    public char[][] rotateTheBox(char[][] box) {\n        int n = box.length;\n        int m = box[0].length;\n\n        // Slide stones down within each row\n        for (int r = 0; r < n; r++) {\n            for (int c = m - 1; c >= 0; c--) {\n                if (box[r][c] == \'#\') {\n                    int col = c;\n                    while (col < m - 1 && box[r][col + 1] == \'.\') {\n                        col++;\n                    }\n                    if (col != c) {\n                        box[r][c] = \'.\';\n                        box[r][col] = \'#\';\n                    }\n                }\n            }\n        }\n\n        // Rotate the box 90 degrees clockwise\n        char[][] ans = new char[m][n];\n        for (int c = 0; c < m; c++) {\n            for (int r = 0; r < n; r++) {\n                ans[c][n - 1 - r] = box[r][c];\n            }\n        }\n\n        return ans;\n    }\n}\n```\n``` JavaScript []\nclass Solution {\n    rotateTheBox(box) {\n        const n = box.length;\n        const m = box[0].length;\n\n        for (let r = 0; r < n; r++) {\n            for (let c = m - 1; c >= 0; c--) {\n                if (box[r][c] === \'#\') {\n                    let col = c;\n                    while (col < m - 1 && box[r][col + 1] === \'.\') {\n                        col++;\n                    }\n                    if (col !== c) {\n                        box[r][c] = \'.\';\n                        box[r][col] = \'#\';\n                    }\n                }\n            }\n        }\n\n        const ans = Array.from({ length: m }, () => Array(n));\n        for (let c = 0; c < m; c++) {\n            for (let r = 0; r < n; r++) {\n                ans[c][n - 1 - r] = box[r][c];\n            }\n        }\n\n        return ans;\n    }\n}\n```\n``` Python []\nclass Solution:\n    def rotateTheBox(self, box):\n        n = len(box)\n        m = len(box[0])\n\n        for r in range(n):\n            for c in range(m - 1, -1, -1):\n                if box[r][c] == \'#\':\n                    col = c\n                    while col < m - 1 and box[r][col + 1] == \'.\':\n                        col += 1\n                    if col != c:\n                        box[r][c] = \'.\'\n                        box[r][col] = \'#\'\n\n        ans = [[None] * n for _ in range(m)]\n        for c in range(m):\n            for r in range(n):\n                ans[c][n - 1 - r] = box[r][c]\n\n        return ans\n\n```
['Depth-First Search', 'Python', 'C++', 'Java', 'JavaScript']