Magic Square Check
grid is a square grid with n rows and n columns, given as a list of rows. It is a magic square when it holds each of the numbers 1 to n * n exactly once and every row, every column and both main diagonals (top-left to bottom-right, and top-right to bottom-left) add up to the same total. Return True if grid is a magic square and False otherwise. Do not change grid.
Example 1
grid [[2,7,6],[9,5,1],[4,3,8]]
returns true
It uses 1 to 9 once each, and every row, column and diagonal adds up to 15.
Example 2
grid [[1,2],[3,4]]
returns false
It uses 1 to 4 once each, but the rows add up to 3 and 7. No 2 by 2 grid can be a magic square.
Constraints
1 <= n <= 6len(grid[r]) == nfor every row-100 <= grid[r][c] <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.