Two Pointers Approach (7ms) and Easy to Understand ;)
Approach :Two PointersComplexity

Time complexity:


Outer Loop (while row < box.length):
This loop runs once for each row in the input box, which has 𝑚 rows. H
# Approach :
# *Two Pointers*

# Complexity
- Time complexity:
   1.  **Outer Loop** (`while row < box.length`):
    This loop runs once for each row in the input box, which has 𝑚 rows. Hence, the outer loop iterates 𝑚 times. 
    2. **Inner Loop** (`for (int j = n - 1; j >= 0; j--)`):
This loop runs for each column in the current row, which has  𝑛 columns. In the worst case, each iteration of the while loop inside may move the pointer i back along the entire row.
    3. **Rotating the Box** (`for (int c = 0; c < n; c++)`):
After processing the row, another loop runs  𝑛 times to populate the rotated array. This is an additional 𝑂(𝑛) work per row.

        # *Total* : *O(m ⋅ n)*

- Space complexity:
    1. **Input Box:** The input `box[][]` is passed as a parameter, which uses 𝑂(𝑚 ⋅ 𝑛) space.

    2. **Rotated Array:** A new 2D array `rotated[][]` of size 𝑛×𝑚 is created to store the rotated result. This uses 𝑂(𝑚 ⋅ 𝑛) space.

    3. **Auxiliary Variables:** Variables such as `row`, `i`, `j`, and `c` are used, which take 𝑂(1) space.
    
        # *Total* : *O(m ⋅ n)*

# Code
```java []
class Solution {
    public char[][] rotateTheBox(char[][] box) {
        int row = 0;
        int n = box[0].length;
        int m = box.length;
        char[][] rotated = new char[n][m];
        while (row < m) {
            int i = n - 1;
            for (int j = n - 1; j >= 0; j--) {
                while (i >= 0 && box[row][i] != '.') {
                    i--;
                    j--;
                }
                if (i > 0 && box[row][j] == '#') {
                    box[row][i] = '#';
                    box[row][j] = '.';
                    i--;
                }
                if (j >= 0 && box[row][j] == '*') {
                    i = j;
                }
            }
            for (int c = 0; c < n; c++) {
                rotated[c][m - row - 1] = box[row][c];
            }
            row++;
        }
        return rotated;
    }
}
```
['Java']