Rotating the Box
Complexity\n- Time complexity: O(n * m)\n\n- Space complexity: O(n * m)\n\n# Code\njava []\nclass Solution {\n    public char[][] rotateTheBox(char[][] box) {\n
# Complexity\n- Time complexity: O(n * m)\n\n- Space complexity: O(n * m)\n\n# Code\n```java []\nclass Solution {\n    public char[][] rotateTheBox(char[][] box) {\n        int n = box.length;\n        int m = box[0].length;\n        char[][] arr = new char[m][n];\n        \n        // Apply gravity to each row\n        for (int i = 0; i < n; i++) {\n            int x = m - 1; // Track the rightmost empty spot\n            for (int j = m - 1; j >= 0; j--) {\n                if (box[i][j] == \'#\') {\n                    // Move the stone to the empty spot\n                    box[i][j] = \'.\';\n                    box[i][x] = \'#\';\n                    x--;\n                } else if (box[i][j] == \'*\') {\n                    // Reset empty spot to just before the obstacle\n                    x = j - 1;\n                }\n            }\n        }\n\n        // Rotate the box 90 degrees clockwise\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                arr[j][n - 1 - i] = box[i][j];\n            }\n        }\n\n        return arr;\n    }\n}\n\n\n```
['Java']