Question bank › Math
Dsa Math Hard

Magic Square Checker

You are given a N x N matrix of integers. Your task is to determine if it forms a magic square. A magic square is defined as a square matrix in which the sum of every row, every column, and both main diagonals are equal. Print 'YES' if it is a magic square and 'NO' otherwise. The first line of input contains the integer N, followed by N lines of N space-separated integers each. Example: Input: 3 8 1 6 3 5 7 4 9 2 Output: YES

Key concepts

matricescombinatoricsmagic squares

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