Dsa
Backtracking
Easy
N-Queens Problem
You must determine all unique solutions for placing N queens on an N×N chessboard so that no two queens threaten each other. Each solution is represented by a list of strings, where '.' represents an empty space and 'Q' represents a queen.
Input format:
- An integer N representing the size of the chessboard.
Output format:
- Each solution should be printed on a new line as a list of strings.
Example:
Input:
4
Output:
[".Q..", "...Q", "Q...", "..Q."]
["..Q.", "Q...", "...Q", ".Q.."]
Key concepts
backtrackingcombinatoricschess
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now