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 counterclockwise can be achieved by taking the transpose of the image matrix and then flipping it on its horizontal axis. *Source: en.wikipedia.org/wiki/Transpose*

Example:

Input image :

1 0

1 0

Modified to :

0 0

1 1

`rotateSquareImageCCW`

to rotate the image counterclockwise - Example:

Input image :

1 0

1 0

Modified to :

0 0

1 1

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 counterclockwise is the same as first taking the transpose of the matrix and then flipping it along its horizontal 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 horizontal axis. If we combine the two - we're done! `transposeMatrix`

+ `flipItHorizontalAxis`

. 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 rotateSquareImageCCW(int[][] matrix) { }

**C**

**Java**

**Python**