Log In

Now, please write a function called that returns the number of N Queens solutions for a chessboard of a given size.

For example, if is 8, then 92 would be returned, because there are 92 possible solutions.

Since we have created , you would go row by row, and call to get the columns in the next row to iterate on, and make a recursive call for each of those values.

In the diagram below, there are 4 choices to put another Queen in the next row. Thus, 4 recursive calls would be made where a different one of those choices is added to the existing list of Queens.

01234567
0
1
2
3
4
5
6
7

When a valid placement of Queens is completed on the last row, a counter should get incremented. At the end, the value of the counter would be returned.

Sign Up or Log In to access the code editor and answer the question!
Log In