Dsa
Matrix
Warm-up
Count Diagonal Elements
Given a square matrix, count the number of elements that are present in both the main diagonal and the anti-diagonal (secondary diagonal).
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 count of overlapping elements.
Example:
Input:
3
1 2 3
4 5 6
7 8 9
Output:
1
Key concepts
matrixcounting
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