Ctrl K

Peaceful Queens

Hard
Place size queens on a size × size chessboard so that none of them attacks another: no two queens may share a row, a column or a diagonal. Return the number of distinct such layouts. Layouts that turn into each other by rotating or mirroring the board count as different.
Example 1
size=5 → 10

A 5×5 board has 10 layouts of five queens in which no queen attacks another.

Example 2
size=2 → 0

Two queens on a 2×2 board always share a row, a column or a diagonal.

Example 3
size=1 → 1
Constraints
  • 1 ≤ size ≤ 9
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsComplete the Sudoku HardPeaceful Queens HardEvery Way to Space the Words HardWords Hidden in a Letter Grid HardSigns Between the Digits Hard
loading Python…
Input
size=5
Expected
10

Run checks the first 3 tests in your browser. Submit checks all 12 tests on the server, hidden ones included.