Dsa
Matrix
Warm-up
Rotating a Matrix
Given a square matrix, rotate it 90 degrees clockwise in place. The rotation should modify the original matrix instead of creating a new one.
Input format:
- The first line contains an integer N, the size of the NxN matrix.
- The next N lines contain N integers each, representing the matrix.
Output format:
- Print the matrix after rotation, 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
matrixarray 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