All practice tasks

Coding (Algo)

Count Non Attacking Queen Placements

Backtracking · Hard

A constraint-search exercise places one queen in every row of an n by n board. No two queens may share a column or diagonal. The task is a specialist backtracking problem: board symmetries are not merged and no board rendering is required.

Count every valid full-board queen placement with no shared row, column or diagonal.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

{ n: integer }

Fields

  • n is the number of rows and columns in the square board.

Output

Return value

  • Return the number of placements, not boards or coordinates. Reflections and rotations count separately when they produce a different placement.
  • The empty board n = 0 has one empty placement. Boards of size two and three have no solution.

Constraints

  • 0 <= n <= 12.

Examples

Example 1

{
  "n": 4
}

Returns

2

Example 2

{
  "n": 2
}

Returns

0

Required complexity

O(n!) search states with conflict pruning and O(n) recursion space

What this task practices

Count Non Attacking Queen Placements is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as hard difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.