Question bank › Matrix
Dsa Matrix Warm-up

Sum of Border Elements

Calculate the sum of all elements that are located on the borders of a given rectangular matrix. The border includes the first and last rows, and the first and last columns of the matrix. Input format: - The first line contains two integers M and N, the dimensions of the grid. - The next M lines contain N integers each, representing the grid. Output format: - Print the sum of the border elements. Example: Input: 3 4 1 2 3 4 5 6 7 8 9 10 11 12 Output: 51

Key concepts

matrixconditionals

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.