/52. Count Distinct N-Queens Solutions

52. Count Distinct N-Queens Solutions

Hard
Backtracking78.3% acceptance

Given an integer board_size, compute the total number of distinct ways to place board_size queens on a board_size x board_size grid such that no two queens threaten each other. Queens threaten each other if they share the same row, column, or diagonal. Return the count of valid arrangements.

Example 1

Input: 2

Output: 0

Explanation: No valid arrangement exists for 2x2 board.

Example 2

Input: 3

Output: 0

Explanation: No valid arrangement exists for 3x3 board.

Example 3

Input: 5

Output: 10

Explanation: There are 10 distinct valid arrangements for 5x5 board.

Constraints

  • 1 <= board_size <= 9
  • Input is a single integer board_size
Python (current runtime)

Case 1

Input: 6

Expected: 4

Case 2

Input: 7

Expected: 40

Case 3

Input: 8

Expected: 92