Question bank › Matrix
Dsa Matrix Medium

Matrix Zigzag Sum

Given a square matrix of integers, compute the sum of the elements that lie on the zigzag diagonal, which starts from the top-left corner, moves to the bottom-right corner, and then continues back to the top-right corner. If the matrix is not square, return 0. Input format: - The first line contains an integer n (1 <= n <= 100), the size of the n x n matrix. - The next n lines each contain n integers, separated by spaces. Output format: - A single integer representing the sum of the zigzag diagonal elements. Example: Input: 3 1 2 3 4 5 6 7 8 9 Output: 30

Key concepts

matrixsummationdiagonal

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.