ALG-H013HardBacktracking
Count Nonattacking Queen Layouts
Place n queens on an n-by-n board so no two share a row, column, or diagonal. Return the number of different valid placements.
Contract
input n: integer
return integer
Constraints
- • 1 <= n <= 10
Examples
Example 1
n = 4
→ 2
Example 2
n = 1
→ 1
5 judge tests (2 shown above). Target complexity: Exponential worst case.