N-Queens

hard

Diagonals are just r−c and r+c, so the safety test is three hash lookups. Rejecting a placement at row 2 kills every branch beneath it - which is where all the performance lives.

Worst O(n!)Space O(n)
Loading the n-queens engine…

Where to go next