[Java] Simulation with explanation O(n) - faster than 100.00%
Java\n\nclass Solution {\n    public char[][] rotateTheBox(char[][] box) {\n        char[][] ans = new char[box[0].length][box.length];\n        for(int i = 0; 
Java\n```\nclass Solution {\n    public char[][] rotateTheBox(char[][] box) {\n        char[][] ans = new char[box[0].length][box.length];\n        for(int i = 0; i < box.length; i++){\n            int j = box[i].length - 1;\n            int pos = j;\n            while(j >= 0){\n                // mark the first (possible) empty position\n                if(box[i][j] == \'*\'){\n                    pos = j - 1;\n                }\n                // move the stone to the first empty position\n                // set the current stone to empty\n                else if(box[i][j] == \'#\'){\n                    box[i][j] = \'.\';\n                    box[i][pos] = \'#\';\n                    // transpose to answer array\n                    ans[pos][ans[0].length - i - 1] = box[i][pos];                \n                    pos--;\n                }\n                // transpose to answer array\n                ans[j][ans[0].length - i - 1] = box[i][j];                \n                j--;\n            }\n        }\n        return ans;\n    }\n}\n```
[]