Runtime Beats 98.04%
ApproachAs gravity takes all the stones towards right, start processign a row form right.
Maintain last index(idx) a stone can be placed. Iterate through row
If
# Approach
As gravity takes all the stones towards right, start processign a row form right.
Maintain last index(idx) a stone can be placed. Iterate through row
1. If current char is stone, swap it with s[idx]
2. If current char is obstacle, reset idx to i - 1. Place at left next to obstacle.


# Complexity
- Time complexity: 
`O(NxM)`
    1. Process 1 row -> `O(cols)`, pocess n rows -> `O(rows x cols)`
    2. Rotation by 90<sup>o</sup> -> `O(rows x cols)`  

- Space complexity:
`O(NxM)`

# Code
```cpp []
class Solution {
public:
    vector<vector<char>> rotateTheBox(vector<vector<char>>& boxGrid) {
        int n = boxGrid.size();
        int m = boxGrid[0].size();

        vector<vector<char>> ans(m, vector<char>(n));

        for(int i=0;i<n;i++) {
            processRow(i, boxGrid); // process current row
            
            for(int j=0;j<m;j++){ // prepare ans grid
                int newRow = j;
                int newCol = n - i - 1;
                ans[newRow][newCol] = boxGrid[i][j]; 
            }
        }

        return ans;
    }

    void processRow(int row, vector<vector<char>>& boxGrid) {
        int n = boxGrid[row].size();
        int idx = n-1;
        for(int i=n-1;i>=0;i--){
            if(boxGrid[row][i] == '*'){
                idx = i-1;
            } else if(boxGrid[row][i] == '#') {
                swap(boxGrid[row][i], boxGrid[row][idx--]);
            } // ignore blank place
        }
    }
};
```
['C++']