TWO POINTER APPROACH
Intuition\nIntution is simple all the stones will fall to the nearest obstacle\n\n\n# Approach\nI have used the "TWO POINTER APPROACH"\n\n# Complexity\n- Time c
# Intuition\nIntution is simple all the stones will fall to the nearest obstacle\n\n\n# Approach\nI have used the "TWO POINTER APPROACH"\n\n# Complexity\n- Time complexity:\nO(m*n)\n\n- Space complexity:\nanswer matrix taking O(m*n)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<vector<char>> rotateTheBox(vector<vector<char>>& box) {\n        vector<vector<char>> ans(box[0].size(), vector<char>(box.size()));\n\n// Here rotating the box 90 degrees without applying Gravitation\n        for (int i = 0; i < box.size(); i++) {\n            for (int j = 0; j < box[0].size(); j++) {\n                ans[j][box.size() - i - 1] = box[i][j];\n            }\n        }\n// If in the rotated box number of rows is one then nothing will be affected from the Gravity(It is not needed since it is being handled by the below code)\n        if(box[0].size()==1)\n        {\n            return ans;\n        }\n// here I am looping through the ans matrix columns and applying two pointer approach to each column separately since gravity only affects vertically\n        for (int i = 0; i < ans[0].size(); i++) {\n// here I am pointing both the pointers to the end of the column and running loop as long as r>=0\n            int l = ans.size() - 1, r = ans.size() - 1;\n            while(r>=0)\n            {\n// here I am running the pointer r until it points to "#" ,while doing this if i come accros any obstacle I will point l to the next of that obstacle i.e l=r-1 (next is r-1 since we are moving from the end to the begining) since stone cannot get past this obstacle\n                while(r>=0&&ans[r][i]!=\'#\')\n                {\n                    if(ans[r][i]==\'*\')\n                    {\n                        l=r-1;\n                    }\n                    r--;\n                }\n// If we did not find any stone then just break \n                if(r<0)break;\n// otherwise swap if (#,.)\n                if(ans[r][i]==\'#\'&&ans[l][i]==\'.\')swap(ans[r][i],ans[l][i]);\n                l--;r--;\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']