Advancedcoding Verified
Place N queens on an N x N chessboard so that no two attack each other; return the solutions or their count (N-Queens).
ReportedSource: GeeksforGeeks interview experience: Apple SDE on-campus 2024
Quick answerFree
Backtrack one queen per row; track used columns, r-c and r+c diagonals in sets (or bitmasks) for O(1) checks; undo after recursion. Exponential, heavily pruned.
Detailed answer· 99 words
Interview PrepUnlock the full answer with Interview Prep
Get a 99-word model answer and a runnable reference solution, plus 28 more Algorithms questions.
Also in Pro (₹499 / 90 days).
Reference solution· runs in the browser sandbox
Interview PrepUnlock with Interview Prep
+ 28 more Algorithms questions in Interview Prep, each with the full answer.