Place n queens on an n×n chessboard so no two attack each other. Watch backtracking try every column on every row, prune the doomed branches, and enumerate every distinct solution. Boards from 4×4 up to 12×12 (one-shot solve up to 16×16).
Click any solution thumbnail below to load it onto the big board.
The N-Queens problem asks for an arrangement of n queens on an n×n board so that no two queens share a row, column, or diagonal. Posed by Max Bezzel in 1848 for n = 8, generalized by Franz Nauck in 1850. There is no solution for n = 2 and n = 3.
Backtracking places one queen per row, trying columns 0 to n−1 and pruning the moment a placement is attacked. The number of distinct solutions grows fast — 92 for n = 8, 14 200 for n = 11, 73 712 for n = 12 — and is sequence A000170 in OEIS.