N-Queens

Place n queens on n×n board with no attacks.

Problem: Place nn queens so none attack each other.

Approach: Place one queen per row via backtracking. Track attacked columns with a set. Track diagonals using rowcolrow - col and row+colrow + col (constant along each diagonal). Skip attacked positions.

Time: O(n!)O(n!) worst case, pruning reduces significantly.

Space: O(n)O(n) for sets and recursion.

See the implementation unit for code.