C++ : Optimal Sol - Easy Peasy Lemon Squeezy
Two steps -\n1. Push all the stones to the right of the row \n2. Rotate the matrix\n\nTime - O(MN)\nSpace - O(MN)\n\n\n\nclass Solution {\npublic:\n    vector<v
**Two steps -**\n1. Push all the stones to the right of the row \n2. Rotate the matrix\n\n**Time - O(MN)**\n**Space - O(MN)**\n\n\n```\nclass Solution {\npublic:\n    vector<vector<char>> rotateTheBox(vector<vector<char>>& box) {\n        int M = box.size();\n        int N = box[0].size();\n        \n        vector<vector<char>> ans(N, vector<char> (M));\n        \n        //Step-1 : Move stones to rightmost side by taking each row separately     \n        for(int i = 0; i < box.size(); ++i) {\n            \n            vector<char> curr = box[i];\n            \n            for(int j = 0, stones = 0, back = 0; j < box[0].size(); ++j) {\n                \n                stones = 0;\n                int inn = 0;\n\t\t\t\t\n\t\t\t\t// counting the number of stones until next obstacle is encountered\n                while(j < box[0].size() && curr[j] != \'*\') {\n                    if(curr[j] == \'#\')\n                        stones++;\n                    ++j;\n                }\n                \n                back = j - 1;\n                \n\t\t\t\t// putting the stones behind the obstacle\n                while(back >= 0 && stones-- > 0) {\n                    curr[back--] = \'#\';\n                    inn = 1;\n                }\n                \n\t\t\t\t// since stones have moved to the right, then overriding the left part with empty spaces\n                while(back >= 0 && inn && curr[back] != \'*\') \n                    curr[back--] = \'.\';\n                \n            }\n\t\t\t\n            box[i] = curr;\n        }\n        \n        //Step-2 : Rotate the matrix\n        for(int i = 0; i < box.size(); ++i) {\n            auto curr = box[i];\n            int row = box[0].size(), col = box.size(); \n            int ii = 0, jj = col - 1 - i, idx = 0;\n            while(ii < row) {\n                ans[ii++][jj] = curr[idx++];\n            }\n        }\n        \n        return ans;\n    }\n};\n```\n\n**Please upvote!!!**
['C']