simplest explanation with java solution
After rotating the array 90\xB0, the right hand side will be the bottom.\n\n\n\n For each row:\n    - empty will point to the last cell that is empty. Initially
After rotating the array 90\xB0, the right hand side will be the bottom.\n\n![image](https://assets.leetcode.com/users/images/3f1cbe44-a529-4a13-9c2c-9968b7741084_1621094504.3116927.png)\n\n* For each row:\n    - `empty` will point to the last cell that is empty. Initially `empty = columns - 1`.\n    - Start from last column in the row, for each column `c`:\n        - if current cell contains a stone, we will move it from current cell to the empty cell(which is represented by `empty` variable).\n        - if current cell contains an obstacle, we will change value of `empty` to `c-1`.\n\nAfter customising the array `box`, we will create another array `box2` which will be rotated version of `box`.\n\n**Why is value of `empty` changed to `c-1` if current cell contains obstacle?**\nLet\'s understand it with the help of an example:\n\n![image](https://assets.leetcode.com/users/images/89551029-e72d-492d-a25b-9d2669f0ef57_1621094520.852314.png)\n\n* The stone at `row = 0` `col = 3` will move to `row = 0` `col = 4`. But The stone at `row = 0` `col = 0` cannot move past obstacle. So it can only move to `row = 0` `col = 1`.\n\n```java\nclass Solution {\n    public char[][] rotateTheBox(char[][] box) {\n        int r = box.length, c = box[0].length;\n        char[][] box2 = new char[c][r];\n        \n        for(int i = 0; i<r; ++i){\n            int empty = c-1;\n            for(int j = c-1; j>=0; --j){\n                if(box[i][j] == \'*\'){\n                    empty = j-1;\n                }\n                if(box[i][j] == \'#\'){\n                    box[i][j] = \'.\';\n                    box[i][empty] = \'#\';\n                    --empty;\n                }\n            }\n        }\n        \n        for(int i = 0; i<r; ++i){\n            for(int j = c-1; j>=0; --j)\n                box2[j][r-i-1] = box[i][j];\n        }\n        \n        return box2;\n    }\n}\n```\n\n**Note - please upvote if you like the explanation. If you have any doubts, please ask in the comment section, I\'ll be happy to answer : )**
[]