Skip to content
DSA Visualizerpreview

N-Queens

Place one queen per row; when a row has no safe square, take back the queen above and move it on.

O(n!) in the worst case time · O(n) space

Board size4

Place 4 queens so that no two share a row, column or diagonal. One queen per row, top to bottom.

4 by 4 board. Queens at nowhere yet.
  1. empty
  • compare
  • swap or write
  • settled

1 / 32

Speed

Space play · ← → step · Home End jump · drag the strip to scrub