HARDasked at 19 companies

N-Queens

A hard-tier problem at 73% community acceptance, tagged with Array, Backtracking. Reported in interviews at TikTok and 18 others.

Founder's read

N-Queens is a classic backtracking problem that shows up across TikTok, Amazon, Google, Microsoft, and Apple interviews. You're placing N queens on an N×N board so no two queens attack each other. Sounds simple until you realize there's no greedy shortcut and brute force is too slow. The acceptance rate is high (73%), but that's because most people who attempt it have already drilled backtracking patterns. If this problem hits your live OA and you blank on the constraint-checking loop or board state management, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
19
Difficulty
HARD
Acceptance
73%

Companies that ask "N-Queens"

If this hits your live OA

N-Queens is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too.

Get StealthCoder
What this means

The trap is thinking you can fill the board row by row without conflict checking. The real work is backtracking: place a queen, validate it doesn't conflict with previous queens, recurse down, then undo. You need to track occupied columns and diagonals efficiently, not re-scan the board each time. Most failures come from either incorrect diagonal math (missing the anti-diagonal offset) or forgetting to remove state when backtracking. The pattern is pure recursion with constraint propagation, and once you see it, it's mechanical. StealthCoder is the safety net if you freeze on the diagonal collision detection or board representation during the live assessment.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

N-Queens recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too. Works on HackerRank, CodeSignal, CoderPad, and Karat.

N-Queens interview FAQ

Why is the diagonal collision check so tricky?+

Two squares are on the same diagonal if the absolute difference of their rows equals the absolute difference of their columns. Many candidates miss that there are two diagonals per square (main and anti-diagonal), and tracking them with offset math is error-prone. Storing occupied diagonals in a set is faster and clearer than re-checking the board each call.

Is N-Queens still asked at FAANG?+

Yes. It appears frequently in reports from Google, Amazon, Microsoft, Apple, and other top companies. It's a canonical backtracking problem, so interviewers use it to gauge whether you understand state management and recursion under constraints, not just memorize solutions.

How does N-Queens relate to the Array and Backtracking topics?+

You represent the board as an array and iterate through it row by row. Backtracking is the core algorithm: you try placing a queen, validate constraints using array state, recurse, then undo. It's the textbook example of how backtracking avoids exploring invalid branches early.

What's the complexity, and does it matter for the interview?+

Time is O(N!) worst case because you explore solutions without pruning invalid branches until late. Space is O(N) for recursion depth plus O(N) for constraint sets. Interviewers don't grill you on big-O here. They care that you prune invalid states early and don't re-scan the board needlessly.

What's the most common mistake on the live OA?+

Forgetting to remove a queen from constraint sets during backtracking, causing false conflicts later. A close second is incorrect diagonal indexing. Both are easy to miss under time pressure. Test with N=4 first to catch these before submitting.

Want the actual problem statement? View "N-Queens" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.