Dsa
Matrix
Medium
Diagonal Difference
Given a square matrix, calculate the absolute difference between the sums of its diagonals. The first diagonal goes from the top left to the bottom right, while the second diagonal goes from the top right to the bottom left.
Input Format:
The first line contains a single integer n, the number of rows and columns in the matrix. The next n lines contain n space-separated integers, representing the elements of the matrix.
Output Format:
Print a single integer, the absolute difference between the sums of the two diagonals.
Example:
Input:
3
1 2 3
4 5 6
7 8 9
Output:
0
Key concepts
matrixdiagonalabsolute
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