Given an integer n, create a matrix of size n by n and fill it with integers from 1 to n * n so that the sum of each row, each column, and the two diagonals are equal. Return the resulting 2D array or null (None in Python) if the task is not possible.
Examples
Example 1
Input
n = 2
Output: []
Explanation:
Filling [1, 2, 3, 4] into a 2 x 2 matrix while satisfying the requirements is not possible, so we return null.
Example 2
Input
n = 3
Output
[[8, 3, 4], [1, 5, 9], [6, 7, 2]]
Explanation
We need to fill [1, 2, 3, 4... 9] into a 3 x 3 matrix. This is one way to do it:
The sum for each row [8, 3, 4], [1, 5, 9], [6, 7, 2] is 15.
The sum for each column [8, 1, 6], [3, 5, 7], [4, 9, 2] is 15.
The sum for each of the two diagonals [8, 5, 2], [4, 5, 6] is 15.