Dsa
Matrix
Easy
Matrix Boundary Sum
Given a matrix of integers, calculate the sum of the boundary elements of the matrix. The boundary elements are those in the first row, last row, first column, and last column.
Input Format:
- The first line contains two integers, R (number of rows) and C (number of columns).
- The next R lines contain C space-separated integers each, representing the matrix.
Output Format:
- A single integer representing the sum of the boundary elements.
Example:
Input:
3 3
1 2 3
4 5 6
7 8 9
Output:
40
Key concepts
matrixprefix sumiteration
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