💡Ultimate Diagram Explanation || ☑️ Beginner Recommended
Youtube Explanation\nSoon to be on Channel : https://www.youtube.com/@Intuit_and_Code\nEdited:\nhttps://youtu.be/EfwIoUdDgcw?si=p9rVyfPumDTQXECG\n\n# Intuition 
# Youtube Explanation\nSoon to be on Channel : https://www.youtube.com/@Intuit_and_Code\nEdited:\nhttps://youtu.be/EfwIoUdDgcw?si=p9rVyfPumDTQXECG\n\n# Intuition and Approach\n![image.png](https://assets.leetcode.com/users/images/b919ca40-96a7-46db-a478-c1bf51a6d2a1_1732350080.2292995.png)\n![image.png](https://assets.leetcode.com/users/images/3617a63d-2fad-4c6b-ac26-5e71e1aabfcf_1732350091.19891.png)\n![image.png](https://assets.leetcode.com/users/images/12995906-fa53-44ae-8e22-e11462469d41_1732350159.815155.png)\n![image.png](https://assets.leetcode.com/users/images/07df3452-847f-432f-9780-982af7babeb3_1732350208.2459292.png)\n![image.png](https://assets.leetcode.com/users/images/b4d3325b-4234-4676-b5f9-d8d05ef7a5bc_1732350236.385391.png)\n![image.png](https://assets.leetcode.com/users/images/71725f35-eb80-49d3-a719-70796b27540f_1732350288.4172273.png)\n![image.png](https://assets.leetcode.com/users/images/b3729328-d8b7-489d-b94f-d693320f0be6_1732350305.583065.png)\n![image.png](https://assets.leetcode.com/users/images/81079365-7f8f-4642-932e-82feaa702f9d_1732350320.017725.png)\n![image.png](https://assets.leetcode.com/users/images/535167ba-ec06-4594-b53b-049b26e160c4_1732350329.1966753.png)\n\n\n# Complexity\n- Time complexity: O(r x c)\n- Space complexity: O(r x c)\n\n# Code\n``` Codes->> [ ]\n```\n```C++ []\nclass Solution {\nprivate:\n    // apply gravity row-wise\n    void solve(vector<char>& s){\n        int l=s.size()-1, r=s.size()-1;\n        while(l>=0){\n            if(s[l]==\'.\'){\n                l--;\n            }\n            else if(s[l]==\'#\'){\n                if(s[r]==\'.\'){\n                    swap(s[r], s[l]);\n                }\n                r--;\n                l--;\n            }\n            else if(s[l]==\'*\'){\n                l--;\n                r=l;\n            }            \n        }\n    }\npublic:\n    vector<vector<char>> rotateTheBox(vector<vector<char>>& box) {\n        for(int row=0;row<box.size();row++){\n            solve(box[row]);\n        }\n\n        // rotate the data\n        int m = box.size(), n = box[0].size();\n        vector<vector<char>> ans(n, vector<char>(m));\n\n        for (int row = 0; row < m; row++) {\n            for (int col = 0; col < n; col++) {\n                ans[col][m - row - 1] = box[row][col];\n            }\n        }\n\n        return ans;\n    }\n};\n```\n``` Java [ ]\nclass Solution {\n    private void solve(char[] s) {\n        int l = s.length - 1, r = s.length - 1;\n        while (l >= 0) {\n            if (s[l] == \'.\') {\n                l--;\n            } else if (s[l] == \'#\') {\n                if (s[r] == \'.\') {\n                    char temp = s[r];\n                    s[r] = s[l];\n                    s[l] = temp;\n                }\n                r--;\n                l--;\n            } else if (s[l] == \'*\') {\n                l--;\n                r = l;\n            }\n        }\n    }\n\n    public char[][] rotateTheBox(char[][] box) {\n        for (int row = 0; row < box.length; row++) {\n            solve(box[row]);\n        }\n\n        int m = box.length, n = box[0].length;\n        char[][] ans = new char[n][m];\n\n        for (int row = 0; row < m; row++) {\n            for (int col = 0; col < n; col++) {\n                ans[col][m - row - 1] = box[row][col];\n            }\n        }\n\n        return ans;\n    }\n}\n```\n``` Py [ ]\nclass Solution:\n    def solve(self, s):\n        l, r = len(s) - 1, len(s) - 1\n        while l >= 0:\n            if s[l] == \'.\':\n                l -= 1\n            elif s[l] == \'#\':\n                if s[r] == \'.\':\n                    s[l], s[r] = s[r], s[l]\n                r -= 1\n                l -= 1\n            elif s[l] == \'*\':\n                l -= 1\n                r = l\n\n    def rotateTheBox(self, box):\n        for row in box:\n            self.solve(row)\n        \n        m, n = len(box), len(box[0])\n        ans = [[None] * m for _ in range(n)]\n\n        for row in range(m):\n            for col in range(n):\n                ans[col][m - row - 1] = box[row][col]\n\n        return ans\n```\n``` Go [ ]\nfunc solve(s []byte) {\n    l, r := len(s)-1, len(s)-1\n    for l >= 0 {\n        if s[l] == \'.\' {\n            l--\n        } else if s[l] == \'#\' {\n            if s[r] == \'.\' {\n                s[r], s[l] = s[l], s[r]\n            }\n            r--\n            l--\n        } else if s[l] == \'*\' {\n            l--\n            r = l\n        }\n    }\n}\n\nfunc rotateTheBox(box [][]byte) [][]byte {\n    for i := 0; i < len(box); i++ {\n        solve(box[i])\n    }\n\n    m, n := len(box), len(box[0])\n    ans := make([][]byte, n)\n    for i := range ans {\n        ans[i] = make([]byte, m)\n    }\n\n    for row := 0; row < m; row++ {\n        for col := 0; col < n; col++ {\n            ans[col][m-row-1] = box[row][col]\n        }\n    }\n\n    return ans\n}\n```\n**[\u2B05\uFE0FPrev](https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows/solutions/6071442/complete-intuition-approach-illustration-beginner-friendly-explained-video)**
['Array', 'Two Pointers', 'Matrix', 'C++', 'Java', 'Go', 'Python3']