Dsa
Matrix
Medium
Boundary Sum
Calculate the sum of the boundary elements of a rectangular matrix. The boundary consists of the first row, last row, first column (excluding corners), and last column (excluding corners).
Input Format:
The first line consists of two integers m and n, the number of rows and columns in the matrix. The next m lines contain n space-separated integers each.
Output Format:
Print a single integer, the sum of the boundary elements.
Example:
Input:
3 4
1 2 3 4
5 6 7 8
9 10 11 12
Output:
45
Key concepts
matrixboundarysum
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