Back
Close
  • 92

Statement

 Goal

We have to place n queens on a chessboard made of n x n squares.
We need to place all of them in such a way that none of them is in direct contact nor attacking another one.
(meaning only one queen is occupying each line, column and diagonal)

Example with n = 4, s = 2 solutions :

- Q - -
- - - Q
Q - - -
- - Q -

and

- - Q -
Q - - -
- - - Q
- Q - -
Input
n : Number of queens (height and width of the cheessboard).
Output
s : Number of solutions.
Constraints
1n11
Example
Input
4
Output
2
Solve it

A higher resolution is required to access the IDE

codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants