Here is the interview question prompt, presented for reference.
Imagine stepping into an interview room, and the interviewer asks you to solve the N-Queen problem. It's a modern take on the classic 8-Queen Puzzle, where you place queens on a chessboard in such a way that none can attack another. Here's a complete guide to understanding the problem and constraints.
First, let's get our chess terminology straight. A queen in chess can move horizontally, vertically, and diagonally. Your task is to place n
queens on an n x n
chessboard in such a way that none of the queens are in a position to attack each other.
n > 3
, at least one non-attacking arrangement of queens exists.n
: The board can have up to 100 rows and columns.n
: The board must have at least 4 rows and columns.O(n^2)
.O(n)
.For a 4x4 chessboard, you could place the queens like so (Q represents a queen, and . represents an empty space):
. Q . .
. . . Q
Q . . .
. . Q .
Here, no two queens threaten each other. And voila, you've successfully solved the 4-queen problem.
Grasp these guidelines well, and you'll be several moves ahead in your coding interview.
You can see the full challenge with visuals at this link.
Challenges • Asked almost 5 years ago by Jake from AlgoDaily
This is the main discussion thread generated for Classical N-Queen Problem.