Dsa
Matrix
Medium
Matrix Diagonal Flip
Write a program that flips a given square matrix along its primary diagonal (top-left to bottom-right). After the flip, the element at matrix[i][j] becomes matrix[j][i].
Input Format:
- The first line contains an integer n, the size of the n x n matrix.
- The following n lines contain n space-separated integers.
Output Format:
- The flipped matrix should be printed, with each row on a new line.
Example:
Input:
3
1 2 3
4 5 6
7 8 9
Output:
1 4 7
2 5 8
3 6 9
Key concepts
matrixdiagonalflip
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