Loading...

The Diagonal Accountant

A easy Python interview practice problem on DataDriven. Write and execute real python code with instant grading.

Domain
Python
Difficulty
easy
Seniority
junior, mid

Problem

A game board validator needs to sum both diagonals of square matrices to verify balance. Write a function that takes a square matrix and returns the sum of both its main diagonal and anti-diagonal. Count the center element once if n is odd.

Practice This Problem

Solve this Python problem with real code execution. DataDriven runs your Python code in a sandboxed Docker environment and grades it instantly.