hardBacktrackingPure DSA~34 min
Rack Placement Without Conflict
On an n × n server rack grid, place n high-heat units so that no two share a row, column, or diagonal cooling channel. Count the number of valid full placements.
Problem
Given an integer n, return the number of distinct ways to place n non-attacking queens on an n × n chessboard (the n-queens problem). No two queens may share a row, column, or diagonal.
Input
An integer n (1 ≤ n ≤ 9).
Output
An integer — the count of distinct valid placements.
Constraints
- Exactly one queen per row and per column in any solution
- 1 ≤ n ≤ 9
- Diagonals: cells share a diagonal when row−col or row+col is equal
Examples
Example 1
Input
n = 4
Output
2
There are exactly two distinct non-attacking arrangements on a 4×4 board.
Example 2
Input
n = 1
Output
1
A single queen on a 1×1 board.