C# | Beats 100%  | O(M * N) | Easy | Detailed Explanation | Cant be easier than this :)
Intuition\n Describe your first thoughts on how to solve this problem. \nInitially, I thought this problem would be challenging to solve, but I managed to figur
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nInitially, I thought this problem would be challenging to solve, but I managed to figure it out and complete it within 30 minutes. The key observation is that when we rotate the box, the rows become columns. So, why not apply gravity first and then perform the rotation?\n \n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst, I will apply gravity to each row to prepare the box for rotation. Once the gravity adjustment is complete, I will proceed to rotate the box. \n# Complexity\n- Time complexity: $$O(M * N)$$ \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(M * N)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```csharp []\npublic class Solution {\n        public char[][] RotateTheBox(char[][] box)\n        {\n            //loop though each row \n            for (var i = 0; i < box.Length; i++)\n            {\n                //apply gravity to each row \n                ApplyGravity(box[i]);\n            }\n            //once we applied the gravity then we should be rotating 90deg and return it \n            return Rotate90Degree(box);\n        }\n\n        /// <summary>\n        /// this method will apply gravity and move objects to left \n        /// </summary>\n        /// <param name="row"></param>\n        private void ApplyGravity(char[] row)\n        {\n            int freePos = row.Length - 1;\n\n            for (var i = row.Length - 1; i >= 0; i--)\n            {\n                if (row[i] == \'*\') //stones cannot fall on or after this \n                {\n                    freePos = i - 1; //so update free position to before this\n                }\n                else if (row[i] == \'#\') //i need to move \n                {\n                    if (freePos != i) //if there is a free space then let it fall \n                    {\n                        row[freePos] = row[i];\n                        row[i] = \'.\';\n                    }\n                    freePos--; //stones wont fall on this so do --\n                }\n            }\n        }\n        /// <summary>\n        /// This method will rotate given matrix by 90deg \n        /// </summary>\n        /// <param name="box"></param>\n        /// <returns></returns>\n        private char[][] Rotate90Degree(char[][] box)\n        {\n            //as we are rotating 90 deg rows will become columns and colums will be rows\n            char[][] rotated = new char[box[0].Length][];\n            for (var row = 0; row < box[0].Length; row++)\n            {\n                rotated[row] = new char[box.Length];\n                for (var col = 0; col < box.Length; col++)\n                {\n                    //as we are rotating 90 deg we need to make sure to swap row and column while copying\n                    //box.Length - j - 1 -- what ever we have at the bottom that will come to top\n                    rotated[row][col] = box[box.Length - col - 1][row];\n                }\n            }\n            return rotated;\n        }  \n}\n```
['C#']