Skip to content
We areTOP 1%

N-Queens

HardLeetCodeBacktracking
Solve on LeetCode(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

Place one queen per row and keep flags for used columns and both diagonals (r + c and r - c), so each placement check is O(1); clear the flags when backtracking.

More in Backtracking

Backtracking questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1PenaltyCodeforcesEasy 1200Solve Penalty on Codeforces (opens in a new tab)
2SubsetsLeetCodeMedium Solve Subsets on LeetCode (opens in a new tab)
3PermutationsLeetCodeMedium Solve Permutations on LeetCode (opens in a new tab)
4Subsets IILeetCodeMedium Solve Subsets II on LeetCode (opens in a new tab)
5Combination SumLeetCodeMedium Solve Combination Sum on LeetCode (opens in a new tab)
6Combination Sum IILeetCodeMedium Solve Combination Sum II on LeetCode (opens in a new tab)
7Dreamoon and WiFiCodeforcesMedium 1300Solve Dreamoon and WiFi on Codeforces (opens in a new tab)
8Lucky Numbers (easy)CodeforcesMedium 1300Solve Lucky Numbers (easy) on Codeforces (opens in a new tab)
9Palindrome PartitioningLeetCodeMedium Solve Palindrome Partitioning on LeetCode (opens in a new tab)
10Berland CrosswordCodeforcesMedium 1400Solve Berland Crossword on Codeforces (opens in a new tab)
11Preparing OlympiadCodeforcesMedium 1400Solve Preparing Olympiad on Codeforces (opens in a new tab)
12a-Good StringCodeforcesMedium 1500Solve a-Good String on Codeforces (opens in a new tab)
13N-QueensLeetCodeHard Solve N-Queens on LeetCode (opens in a new tab)
14Sudoku SolverLeetCodeHard Solve Sudoku Solver on LeetCode (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account