Count N-Queens Solutions
hard · backtracking
Return the number of ways to place n queens on an n-by-n board with no shared row, column, or diagonal. Count distinct board arrangements; rotations/reflections count separately. n is an integer from 0 to 9. By convention n=0 has one empty arrangement. Return only the count, not board layouts.
Examples (JSON; null means Python None):
Input: {"n": 4}
Output: 2
Input: {"n": 1}
Output: 1
Starter code
def count_queens(n: int) -> int:
"""Count boards by reserving columns and both diagonal families."""
pass
Loading editor…
Each test has a five-second execution limit. Your practice drafts and solved progress stay in this browser.
Return to the Python compiler