Skip to content
BytePatterns

Count Queen Placements

HardBacktracking#backtracking#constraint-sets~40m

Problem

On an n by n chessboard, place n queens so that no two of them share a row, a column or a diagonal. Return how many different placements exist. The board size n is at least 1.

Examples

Input:  n = 4
Output: 2
Why:    the two placements are mirror images of each other
Input:  n = 1
Output: 1
Why:    a single queen on a single square attacks nothing
Input:  n = 3
Output: 0
Why:    edge case, small boards can have no valid placement at all

Hints

0 / 3

Stuck on the idea rather than the code? N-Queens covers it.