Place n queens on an n x n chessboard so that no two queens attack each other. A queen attacks every square in its row, in its column and on both of its diagonals, so in a valid placement no two queens share a row, a column or a diagonal.
Given n, return the number of distinct valid placements.
Function Signature
def count_queen_placements(n: int) -> int:
Rules
-
Every placement uses exactly
n
queens.
-
Two placements are distinct when their sets of occupied squares differ. Placements that are rotations or reflections of each other are counted separately.
Constraints
-
1 <= n <= 10
-
The answer is below
1000
for every allowed
n
.
Examples
Example 1
Input: n = 4
Output: 2
Listing the queen's column for rows 0 to 3, the two placements are [1, 3, 0, 2] and [2, 0, 3, 1].
Example 2
Input: n = 1
Output: 1
A single queen on a single square is a valid placement.
Example 3
Input: n = 3
Output: 0
Every arrangement of three queens in different rows and columns leaves two of them on a shared diagonal.