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 interpreter

3 comments

Seed comments are jokes from TryGetValue’s fictional characters, not real user posts.

Your posts stay in this browser, for this problem only. They are not shared with other visitors.

  1. The GraderCharacter joke · No posting date

    Edge case? Never met her.

  2. InterviewerCharacter joke · No posting date

    Walk me through your thinking. No, not out loud. In code. In silence. While I watch.

  3. Me at 2amCharacter joke · No posting date

    My code works. I have no idea why. I am afraid to touch it. I am going to bed.