A matrix of size nxn
needs to be constructed with the desired properties.
n
is even. (given as input to the algorithm)- Matrix should contain integers from
0
ton-1
- Main diagonal should contain only zeroes and matrix should be symmetric.
- All numbers in each row should be different.
For various n
, any one of the possible output is required.
input
2
output
0 1
1 0
input
4
output
0 1 3 2
1 0 2 3
3 2 0 1
2 3 1 0
Now the only idea that comes to my mind is to brute-force build combinations recursively and prune.
How can this be done in a iterative way perhaps efficiently?