Skip to main content
Hard Backtracking Medium frequency

N-Queens

Open on LeetCode

Approach Summary

Place queens row by row. Track used columns, diagonals (/), and anti-diagonals (\). Backtrack on conflicts.

How to Recognize This Pattern

  • Place one per row; conflict check with col and two diagonal sets
  • Classic constraint-satisfaction backtracking

Complexity Analysis

Time Complexity

O(n!)

Space Complexity

O(n)

Tags

Array Backtracking

This site is free. If these guides are helping your prep, consider buying me a coffee. ☕

Support →
Buy me a coffee