function isValid(state) {
const size = state.length;
const boxSize = Math.sqrt(size);
for (let i = 0; i < size; i += 1) {
const row = [];
const column = [];
const box = [];
const i0 = (i % boxSize) * boxSize;
const j0 = Math.floor(i / boxSize) * boxSize;
for (let j = 0; j < size; j += 1) {
row.push(state[i][j]);
column.push(state[j][i]);
const i1 = (j % boxSize);
const j1 = Math.floor(j / boxSize);
box.push(state[i0 + i1][j0 + j1]);
}
if (!(isUnique(row) && isUnique(column) && isUnique(box))) {
return false;
}
}
return true;
}