Notice Period

Count the Queen Layouts

hard

A puzzle app needs to know how many solutions each board size has before generating daily challenges.

Given an integer n, count the number of ways to place n chess queens on an n × n board so that no two queens attack each other — no shared row, column, or diagonal. Return the count of distinct layouts.

Example 1
in n = 4
out 2
The two solutions are mirror images of each other.
Example 2
in n = 1
out 1
Example 3
in n = 3
out 0
Three queens cannot avoid each other on a 3×3 board.
Constraints
  • · 1 <= n <= 8
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.