Medium · Transpose + Reverse
Understand → Visualise → Practice.
Return a new square matrix rotated 90 degrees clockwise.
After a clockwise turn, the new row c is the old column c read from bottom to top: new[c][r] = old[n − 1 − r][c].
Make an n × n output matrix.
new[col][row] = old[n − 1 − row][col].
In place, transposing and then reversing each row gives the same rotation.
O(n²) time and O(n²) output space.
Using the original row and column directly performs a transpose, not a rotation.
Read the full guide first: Matrices and 2-D Arrays.
Guest mode lets you understand, visualise and run the sample tests. Create a free account to submit and save your solutions.