Java | Runtime: 8 ms, faster than 93.33% of Java online submissions
Here, a countis taken which counts the no. of empty spaces from the end of each row. Incase a stone is encountered, the stone is shifted down in the column by c
Here, a ```count```is taken which counts the no. of empty spaces from the end of each row. Incase a stone is encountered, the stone is shifted down in the column by ```count```times. If an obstacle is encountered ```count```is made 0 as obstacle does not shift and stones above it will fall on it.\n```\npublic char[][] rotateTheBox(char[][] box) {\n        int m = box.length, n = box[0].length;\n        char ans[][] = new char[n][m];\n        int count;\n        for(int i = 0 ; i < m ; i++) {\n            count = 0;\n            for(int j = n - 1 ; j >= 0 ; j--) {\n                if(box[i][j] == \'.\') {\n                    count++;\n                    ans[j][m - i - 1] = \'.\';\n                }\n                else if(box[i][j] == \'*\') {\n                    count = 0;\n                    ans[j][m - i - 1] = \'*\';\n                }\n                else {\n                    if(count == 0)\n                        ans[j][m - i - 1] = \'#\';\n                    else {\n                        ans[j][m - i - 1] = \'.\';\n                        ans[j + count][m - i - 1] = \'#\';\n                    }\n                }      \n            }\n        }\n        return ans;\n    }\n```
['Java']