Rotate Image
Medium Math & Geometry
matrix is a square grid of whole numbers, with n rows and n columns.
Turn it a quarter turn clockwise: the number in row i and column j moves to row j and column n - 1 - i, counting rows and columns from 0. So the first row becomes the last column, and the last row becomes the first column.
Change matrix in place, so that it holds the turned grid when your function ends. Return nothing.
Example 1
The first row, 2 7 1, becomes the last column, read from top to bottom. The last row, 0 5 8, becomes the first column. The -4 in the middle has nowhere to go and stays.
Example 2
Example 3
Constraints
1 ≤ n ≤ 500matrixhasnrows, and every row hasnnumbers-1000 ≤ matrix[i][j] ≤ 1000
Solve it here
Write it in Python, Java or C++, run it on your own cases, and submit against hidden tests.
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
See the AI roundWatch the explanation
More Math & Geometry
- Roman to IntegerAI round · Easy
- Palindrome NumberAI round · Easy
- Count PrimesAI round · Medium
- Reverse IntegerMedium
- Integer to RomanMedium