25. N-Queens
Place n queens on an n × n chessboard so that no two share a row, a column or a diagonal. Write totalNQueens n, the number of different placements.
The eight-queens puzzle has 92 solutions. The hidden tests go up to n = 9.
Examples
- Input
totalNQueens 4Output2 - Input
totalNQueens 1Output1
Submitting also runs 8 hidden tests.
Constraints
totalNQueens 0 = 1: the empty board is one placement.
Running and submitting solutions, the hints and the editorial come with the Academy Pass. The daily problem is open to every account.
Loading editor…
Type
\to in the editor, or click:Run checks your code against the examples and your custom inputs and records nothing. Submit also runs the hidden tests, confirms the axioms your proof uses and records the result. Each uses one compiler check.
ReadyLn 1, Col 1Lean 4
Draft saved in this browser