Simple py,JAVA code explained in detail!!!
Problem understanding\n- This is intresting and a very easy problem,read the question properly and understand what they are asking us to do!\n- Then let\'s star
# Problem understanding\n- This is intresting and a very easy problem,read the question properly and understand what they are asking us to do!\n- Then let\'s start,we are given a *matrix* named `box` what we should do is to *roatate the box* by $90^*$.\n- Not only that,there are some `2` kinda items inside it,let\'s say `3` for now.\n  - A **stone** denoted by `#`.\n  - A **STATIONARY OBSTACLE** denoted by `*`.\n  - then a *Empty space* denoted by `.`.\n- what we have to do is to apply ***gravity effect***  on the box.\n- what is **GRAVITY EFFECT?** objects fall down *All objects have a tendency to fall towards the Earth when thrown up/under free fall due to the influence of gravity* \n- The objects `#` falls down under gravity so it may stop only when it meets another stone `#` or `*` or *BOTTOM OF BOX.*\n- And to note *stationary obstacles* `*` remain intact,doesn\'t move down under influenece of `g`. \n---\n\n# Approach:Two pointer\n<!-- Describe your approach to solving the problem. -->\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- So what\'s my first though here was to ***simulate*** the whole thing,the exact working => **rotation+gravity effect**.To achieve this I used two pointer.\n- But I didn\'t do that way with two pointer I first did **gravity effect** then **roation**.\n- what we can observe is *gravity effect* is ***independent*** for each single row/column if we are seeing from horizonatal and vertical perspective.\n- I always try to look up in *horizontal* perspective since it\'s easy to understand and manupulate.\n- we will have a varaible `index` which is always set to *end of row*,so it handles the edge case of my logic **THE END OF BOX**,it also determines the position of empty space `.`.\n- for each `row` in the `matrix` we will apply the below _gravity-2pointer algo_\n    - if we see a *stone* `#` we mark that index as `start` then we look for next `free space` that is `.` using `end` pointer that is next index to `start`(`start+1`).Then `index` is set to `end`.\n    - we imediatley stop when we see `*` coz,we can\'t cross through it,and break the loop and we manage `index` as `start` itself.\n- If we find a empty space we normally swap it,if not found then we swap it with box last element,if obstale found we swap it with it\'s position itself.     \n\n# Complexity\n- Time complexity:$O(n^2)$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$O(n^2)$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```Python3 []\nclass Solution:\n    def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]:\n        def display(mat):\n            for row in mat:\n                print(row)\n            print(\'-----------------------\')\n        #display(box)\n        for row in box:\n            for start in range(len(row)):\n                if row[start]==\'#\':\n                    index=len(row)-1\n                    for end in range(start+1,len(row)):\n                        if row[end]==\'*\':\n                            index=start\n                            break\n                        if row[end]==\'.\':\n                            index=end\n                            break\n                    row[start],row[index]=row[index],row[start]\n        #display(box)\n        newBox=[[\'\']*len(box) for _ in range(len(box[0]))]\n        #display(newBox)\n        for i in range(len(box)):\n            for j in range(len(box[0])):\n                newBox[j][len(box)-1-i]=box[i][j]\n            print(\'----------------------------\')\n        #display(newBox)\n        return newBox\n\n```\n```java []\nclass Solution {\n    public char[][] rotateTheBox(char[][] box) {\n        for(char[] row:box){\n            for(int start=0;start<row.length;start++){\n                if(row[start]==\'#\'){\n                    int index=row.length-1;\n                    for(int end=start+1;end<row.length;end++){\n                        if(row[end]==\'*\'){\n                            index=start;\n                            break;\n                        }\n                        else if(row[end]==\'.\'){\n                            index=end;\n                            break;\n                        }\n                    }\n                    char temp=row[index];\n                    row[index]=row[start];\n                    row[start]=temp;\n                }\n            }\n        }\n        char[][] newBox=new char[box[0].length][box.length];\n        for(int i=0;i<box.length;i++){\n            for(int j=0;j<box[0].length;j++){\n                newBox[j][box.length-1-i]=box[i][j];\n            }\n        }\n        return newBox;\n    }\n}\n```
['Array', 'Two Pointers', 'Matrix', 'Java', 'Python3']