HARDasked at 7 companies

N-Queens II

A hard-tier problem at 77% community acceptance, tagged with Backtracking. Reported in interviews at Zenefits and 6 others.

Founder's read

N-Queens II cuts straight to the solve: count the number of valid placements, not enumerate them. You've likely drilled the original N-Queens problem. This variant trips candidates because they build the full solution set then count, burning time and memory. Zenefits, Google, Amazon, and Microsoft ask this. The acceptance rate sits near 77%, which means most people who attempt it know backtracking exists. The catch is efficiency. If you blank on the pruning strategy during your live OA, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
7
Difficulty
HARD
Acceptance
77%

Companies that ask "N-Queens II"

If this hits your live OA

N-Queens II 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. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.

Get StealthCoder
What this means

The trick is to avoid storing each solution. Instead, count valid placements as you backtrack. The naive approach builds all n! candidate arrangements then filters for conflicts. The correct approach prunes the search tree early by tracking column and diagonal occupancy in sets, eliminating impossible branches before they spawn. Most candidates spend time reconstructing board state for each solution. You don't. You track only the queen positions in the current row, validate diagonals (sum of row and column indices for one diagonal, difference for the other), and return a count. The backtracking frame stays the same. The constraint checking is identical. The only difference is your output: a number, not a list of lists. Common failure: forgetting that diagonals map to unique sums and differences. If you hit this problem live and the pattern doesn't click, StealthCoder runs invisibly and hands you the working template.

Pattern tags

The honest play

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

N-Queens II 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. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.

N-Queens II interview FAQ

Is N-Queens II actually asked at FAANG, or is it just the original problem?+

Both versions appear. Google, Amazon, and Microsoft have all reported asking this variant. The II suffix signals they want the count, not the boards themselves. It's a way to filter for candidates who optimize rather than brute force. If you see 'count all solutions' in the problem statement, you're on this path.

What's the core difference between N-Queens and N-Queens II algorithmically?+

Both use backtracking and identical constraint validation. The difference is output. N-Queens II skips board reconstruction and list appends. You return an integer. This saves memory and forces you to think about the search tree shape rather than solution storage. Pruning logic stays the same.

How do you check diagonals without a full 2D board?+

Use two sets: one for row+col sums, one for row-col differences. Each queen occupies a unique sum and difference on its diagonals. When placing a queen at (row, col), check if row+col or row-col is already occupied. If yes, that queen placement is invalid. No 2D array needed.

Why do most candidates fail this if backtracking is the known topic?+

They write correct backtracking but store solutions. For n=8, that's 92 lists in memory. They also reconstruct the board state for each solution, which is wasted work. Acceptance is 77%, not higher, because candidates solve it the hard way and hit time/memory limits on larger n.

Does this problem appear at companies like Bloomberg and Snowflake too?+

Yes. Both have reported asking it. It's not exclusive to FAANG. It's a standard backtracking problem across mid to large tech companies. The variant (count vs. enumerate) matters because it tests whether you understand algorithmic efficiency, not just whether you know the pattern.

Want the actual problem statement? View "N-Queens II" 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.