After being able to validate whether a Queen placement is valid, we can use it to write a function called
. It would return the columns in the next row that the existing Queens cannot visit, so the partial solution with an additional Queen would succeed.
The first parameter is
and determines the size of the chessboard.
The second parameter is
, which is an array of Queen positions. It is an array of arrays- the first value of the array is the row, and the second value is the column.
The third parameter is
, which is an integer of the row to check.
The diagram above illustrates the following parameters:
var = 8; = 8
var = [[0,1],[1,3]]; = [[0,1],[1,3]]
var = 2; = 2
[0, 5, 6, 7] in this case. The column values must be in ascending order.
If there are no columns to check, return an empty array.