grid. Add up every number on the main diagonal (top-left to bottom-right) and on the anti-diagonal (top-right to bottom-left).
When n is odd, the two diagonals meet in the centre cell; count its value only once.
Return the total.grid=[[2, 4, 6], [1, 3, 5], [8, 7, 9]] → 28
Main diagonal: 2 + 3 + 9; anti-diagonal: 6 + 8 (the centre 3 is already counted). Total 28.
grid=[[1, 2], [3, 4]] → 10
In a 2×2 grid the diagonals do not cross: 1 + 4 + 2 + 3 = 10.
grid=[[7]] → 7
len(grid) == len(grid[i])grid[i][j] ≤ 100grid=[[2, 4, 6], [1, 3, 5], [8, 7, 9]]
28
Run checks the first 3 tests in your browser. Submit checks all 41 tests on the server, hidden ones included.