Very Easy Two Approaches Clean Code in C++ || Beats 100% in runtime & 99% space
\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n-
![image.png](https://assets.leetcode.com/users/images/3dc370e1-06bb-4f10-acc3-1c669772ef6f_1732340759.6247106.png)\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(N * M)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N*M)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Optimal Code: O(N*M) Time\n```cpp []\n#pragma GCC optimize("03","Ofast","unroll-loops")\n#pragma GCC target("avx")\nstatic const auto harsh = [](){\n\tios_base::sync_with_stdio(0);\n\tcin.tie(0);\t\n\tcout.tie(0);\n\treturn \'c\';\n}();\n\nclass Solution {\npublic:\n    vector<vector<char>> rotateTheBox(vector<vector<char>>& box) {\n        int n = box.size();\n        int m = box[0].size();\n        vector<vector<char>> mp(m, vector<char>(n, \'.\'));\n\n        for(int i = n-1; i>=0; i--){\n            for(int j = 0; j<m; j++){\n                mp[j][n-i-1] = box[i][j];\n            }\n        }\n\n        for(int j = 0; j<n; j++){\n            int temp = -1;\n            for(int i = m-1; i>=0; i--){\n\n                if(mp[i][j] == \'#\' && temp != -1){\n                    // First Mmark it as a empty we assume this have fallen\n                    mp[i][j] = \'.\';\n\n                    // set this where it should be after fallen\n                    mp[temp][j] = \'#\';\n                    temp--;         \n                }\n                else if(mp[i][j] == \'.\' && temp == -1){\n                    temp = i;\n                }\n                // If we encounter by any obstacle or another stone then make temp = -1\n                else if(mp[i][j] == \'#\' || mp[i][j] == \'*\'){\n                    temp = -1;\n                }\n            }\n        }\n\n        return mp;\n    }\n};\n```\n\n# Brute Forced: O(N * M * M) Time\n```cpp []\n#pragma GCC optimize("03","Ofast","unroll-loops")\n#pragma GCC target("avx")\nstatic const auto harsh = [](){\n\tios_base::sync_with_stdio(0);\n\tcin.tie(0);\t\n\tcout.tie(0);\n\treturn \'c\';\n}();\n\nclass Solution {\npublic:\n    vector<vector<char>> rotateTheBox(vector<vector<char>>& box) {\n        int n = box.size();\n        int m = box[0].size();\n        vector<vector<char>> mp(m, vector<char>(n, \'.\'));\n\n        for(int i = n-1; i>=0; i--){\n            for(int j = 0; j<m; j++){\n                mp[j][n-i-1] = box[i][j];\n            }\n        }\n\n        for(int j = 0; j<n; j++){\n            for(int i = m-1; i>=0; i--){\n\n                if(mp[i][j] == \'#\'){\n                    // First Mmark it as a empty we assume this have fallen\n                    mp[i][j] = \'.\';\n\n                    int k = i+1;\n                    while(k < m && mp[k][j] == \'.\'){\n                        k++;\n                    }\n\n                    // set this where it should be after fallen\n                    mp[k-1][j] = \'#\';         \n                }\n            }\n        }\n\n        return mp;\n    }\n};\n\n```
['Array', 'Two Pointers', 'Matrix', 'C++']