Title
N Queen Problem
Problem
Given the size of a chessboard and the number of Queens n as an input parameter, write a solution function that returns the number of possible ways to place n Queens on an n n chessboard such that no two Queens attack each other.
Background Information
- The N-Queen problem is a classical problem in which
nQueens are placed on annnchessboard such that no two Queens attack each other. - A Queen can attack any other piece in all vertical, horizontal, and diagonal directions, regardless of distance.
Constraints
nis a natural number between 3 and 12, inclusive.
Test Case Explanation
| Test Case Number | n | return |
|---|---|---|
| 1 | 3 | 0 |
| 2 | 5 | 10 |
| 3 | 8 | 92 |
Explanation for Test Case 1
- For a 3 3 chessboard, it is impossible to place 3 Queens such that no two Queens attack each other. Thus, the result is 0.
Explanation for Test Case 2
- For a 5 5 chessboard, there are 10 ways to place 5 Queens such that no two Queens attack each other.
- One of these arrangements is shown below:

Explanation for Test Case 3
- For an 8 8 chessboard, there are 92 ways to place 8 Queens such that no two Queens attack each other.
- One of these arrangements is shown below:
