N-Queens - Placement Count - aloalgo

N-Queens - Placement Count

Hard

You are given an integer n.

Your task is to find the total number of distinct ways to place n chess queens on an n x n chessboard such that no two queens threaten each other.

Note that:

  • Two queens threaten each other if they share the same row, column, or diagonal.

Return the total number of distinct ways.

Example 1

Input
1
Output
1
Explanation:

For a 1x1 board, there is only one solution: placing the queen at the single cell.

Example 2

Input
3
Output
0
Explanation:

For a 3x3 board, it's impossible to place 3 queens without any two attacking each other.

Example 3

Input
4
Output
2
Explanation:

For a 4x4 board, there are two distinct ways to place 4 queens such that no two queens threaten each other.

Loading...
Input
1
Output
1

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!