51. N-Queens

Hard — Backtracking

Backtracking + Sets
Bitmask
Brute (Permutations)
Press "Play" or "Step" to walk through the search.

Step

0 / 0

Placements

0

Backtracks

0

Solutions Found

0
Trying
Queen placed
Solution row
Attacked
Current row
Algorithm Complexity (smaller bar = faster)
Brute Permutations
O(n! · n²)
Time / Space: O(n!·n²) / O(n)
Backtracking + Sets
O(n!) pruned
Time / Space: O(n!) / O(n)
Backtracking + Bitmask
O(n!) bitwise
Time / Space: O(n!) / O(n)