Easy Code Beats 90% using Brute Force
Intuition\nMy initial thought was just to traverse through the vector and keep swapping the two elements of the vector if the current element is a # and the nex
# Intuition\nMy initial thought was just to traverse through the vector and keep swapping the two elements of the vector if the current element is a `#` and the next element is a `.` . \n\n# Approach\n1.) We first initialise a vector `nums` with dimensions opposite of that of our initial vector box.\n2.) We then traverse through this vector starting from the end of the row and then just keep checking that if the element is a `*` then we update empty to the element before the `*` as any element falling before `*` would hit this point.\n3.) We just keep traversing and check if there is a `#` present then we swap it directly with empty or the directly move it to the free space before the obstacle where the block should technically next move.\n4.) Lastly we just print the elements in reverse i.e -->\n* Elements were input in the form n x m.\n* We print elements out in the form m x n. (its rotated)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<vector<char>> rotateTheBox(vector<vector<char>>& box) {\n        int n = box.size();\n        int m = box[0].size();\n        // Resulting vector after rotation\n        vector<vector<char>> nums(m, vector<char>(n, \'.\'));\n        for (int i = 0; i < n; i++) {\n            int empty = m - 1; // Start from the end of the row\n            for (int j = m - 1; j >= 0; j--) {\n                if (box[i][j] == \'*\') {\n                    empty = j - 1; // Update empty to just before the obstacle\n                } else if (box[i][j] == \'#\') {\n                    // Swap the stone to the \'empty\' position\n                    swap(box[i][j], box[i][empty]);\n                    empty--; // Move the empty position backward\n                }\n            }\n            // Insert the processed row into the rotated matrix\n            for (int j = 0; j < m; j++) {\n                nums[j][n - i - 1] = box[i][j];\n            }\n        }\n        return nums;\n    }\n};\n\n```
['C++']