Dsa
Matrix
Easy
Matrix Rotation by 90 Degrees
Rotate a square matrix (N x N) by 90 degrees clockwise. The rotation should be done in place, meaning you should not use any extra space for a new matrix.
Input Format:
- The first line contains an integer N (the dimensions of the matrix, N x N).
- The next N lines contain N space-separated integers each, representing the matrix.
Output Format:
- Print the rotated matrix with each row on a new line.
Example:
Input:
3
1 2 3
4 5 6
7 8 9
Output:
7 4 1
8 5 2
9 6 3
Key concepts
matrixrotationarray manipulation
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now