Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

Boss fightThe Queen Citadel

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Guard columns and both diagonal families: The Queen Citadel.

Brute force may pass the demo but fail when the world fills with players.

How you win

  1. 1Recognize when N-Queens backtracking matches the clues
  2. 2Keep this true after every move: the partial board has one queen per completed row and no shared column or diagonal
  3. 3Reach the result within O(n!) search with constant-time conflict checks

Rules and pressure

  • Target cost: O(n!) search with constant-time conflict checks
  • State rule: the partial board has one queen per completed row and no shared column or diagonal
Lesson 1 of 3

Live algorithm trace

N-Queens backtracking

Complete execution
1 of 5
.Q..
row
...Q
Q...
..Q.
cols
diags

The first row may try every column.

1search(row)
2if row == n: record board
3for each column
4skip occupied column or diagonal
5place queen and mark three sets
6recurse, then remove queen and marks
row = 0available = 0,1,2,3
Truth to preserve / Cost target
Truth to preserve

the partial board has one queen per completed row and no shared column or diagonal

Cost target

O(n!) search with constant-time conflict checks

Place one queen per row. Sets for columns, row-minus-column diagonals, and row-plus-column diagonals reject every attacked square in constant time.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead