You are given a square 2D image matrix where each integer represents a pixel. Write a method **in-place**. This problem can be broken down into simpler sub-problems you've already solved earlier! Rotating an image clockwise can be achieved by taking the transpose of the image matrix and then flipping it on its vertical axis.

**Example:**Input image :

1 0

1 0

Modified to :

1 1

0 0

`rotateSquareImageCW`

to rotate the image clockwise - 1 0

1 0

Modified to :

1 1

0 0

Need a **hand?** Try out these hints, one at a time.

Remember that if you modify an input parameter that is of type Array in Java, you're actually modifying the object itself! That's why the return type is void.

Image Rotation can be simplified if you can break up the process into smaller sub-problems. Rotating a matrix clockwise is the same as first taking the transpose of the matrix and then flipping it along its vertical axis!

Remember this pattern for all 2D array problems :

`int rows = matrix.length`

and `int columns = matrix[0].length`

. In your learning program you may have come across the following sub-problems - Find the transpose of a square matrix and Flip an image on its vertical axis. If we combine the two - we're done! `transposeMatrix`

+ `flipItVerticalAxis`

. As a refresher, here's the pattern for getting the transpose of a matrix : for(int i = 0; i <= n; i++){

for(int j = i+1; j <= n; j++){

int temp = matrix[i][j];

matrix[i][j] = matrix[j][i];

matrix[j][i] = temp;

}

}

public static void rotateSquareImageCW(int[][] matrix) { }

**C**

**Java**

**Python**