

You are given ‘N’ = 3, the matrix formed such that sum of rows, columns, and two diagonals are equal is
[[8, 3, 4],
[1, 5, 9]
[6, 7, 2]]
The first line of input contains the integer ‘T’ representing the number of test cases.
The first line of each test case contains the single integer ‘N’ representing the given integer.
For each test case, print ‘CORRECT’ if the returned matrix is correct, print ‘NULL’ if it’s impossible to form the matrix with the given number.
Print a separate line for each test case.
1 <= T <= 10
1 <= N <= 1000
Time Limit: 1 sec
In this approach, we will try to place every available number at a current position and check if the matrix is valid. We will keep track of the number we have already placed, so we don’t place twice.
We will create two functions checkFunction(ans) to check if the ans matrix is valid. fillMatrixUilt(n, mat, nums, row, col) is the backtracking function, where n is the number given, mat is the matrix. array keeps track of the used numbers and row, col is the current row and column of the matrix.
Algorithm:
In this approach, we will fill the matrix by building the matrix from the inside out. There are 3 cases for the matrix.
We will create 3 functions fillMatrixEven(N), fillMatrixOdd(N), fillMatrixDoublyEven(N) where N is the given integer.
Algorithm:
We will create 3 functions fillMatrixEven(N), fillMatrixOdd(N), fillMatrixDoublyEven(N) where N is the given integer.
Algorithm: