Backtracking•Pattern: Backtracking•Medium

N-Queens — place N queens on N×N board without conflict

Problem Intuition & Objective

Find all valid N-Queens placements.

Time ComplexityO(n!)
Optimal
Space ComplexityO(n)
Memory Bounds
Optimal Algorithmic Approach

Row-by-row backtracking with column and diagonal conflict sets.

Core Invariants & Edge Cases

  • Place one queen per row; track used columns and both diagonals
  • Diagonals: col-row is unique for '/' diagonal, col+row for '\'
  • Use sets to check conflicts in O(1)
Previous ProblemLetter combinations of a phone numberNext Problem Palindrome partitioning

System Design & Architecture Roadmap

Coding interviews are only 50% of the bar. Master High-Level Design, distributed systems, and Object-Oriented LLD.