#C3640. Rotate Matrix

    ID: 47090 Type: Default 1000ms 256MiB

Rotate Matrix

Rotate Matrix

You are given an N x N matrix. Your task is to rotate the matrix by 90° clockwise in-place. That is, you should modify the matrix directly without using additional memory for another matrix.

The rotation process involves two steps:

  • First, transpose the matrix (i.e., swap matrix[i][j] with matrix[j][i]).
  • Then, reverse each row.

Constraints:

  • 1 ≤ N ≤ 20
  • -1000 ≤ matrix[i][j] ≤ 1000

Example 1:

Input:
3
1 2 3
4 5 6
7 8 9

Output: 7 4 1 8 5 2 9 6 3

</p>

Example 2:

Input:
4
5 1 9 11
2 4 8 10
13 3 6 7
15 14 12 16

Output: 15 13 2 5 14 3 4 1 12 6 8 9 16 7 10 11

</p>

inputFormat

The first line of input contains a single integer N, which represents the dimensions of the matrix. The following N lines each contain N space-separated integers representing the rows of the matrix.

outputFormat

Output the rotated matrix. Each of the N lines should contain N space-separated integers representing the rows of the rotated matrix.

## sample
3
1 2 3
4 5 6
7 8 9
7 4 1

8 5 2 9 6 3

</p>