N-Queens — Backtracking, Row by Row

Place one queen per row. Before each placement, check the column, main diagonal (r−c), and anti-diagonal (r+c). On a dead-end row, backtrack: lift the last queen and try the next column.

step 0

Board (current attack highlights)

attacked column attacked diagonals trying this square ♛ placed queen
Press Step to begin. We try columns left to right in each row; the first safe square gets a queen.

Search state

row 0
trying col
nodes 0
backtracks 0
solutions 0
queens placed 0
pos[] = []
cols
r−c
r+c
Self-contained visualization. Conflict checks are O(1): a square (r,c) is safe iff its column c, main diagonal r−c, and anti-diagonal r+c are all free. See junior.md for the recursion and middle.md for the bitmask speedup; professional.md proves the search visits exactly the valid partial placements.