Back to DSA
N-Queens
hardPlace n queens on an n-by-n chessboard so that no two queens threaten each other. Queens attack along rows, columns, and both diagonals. Return every distinct valid arrangement, where each arrangement is represented as a list of strings showing the board.
Examples
Example 1:
Input:
n = 5Output:
10 solutions exist (e.g. ["Q....","..Q..","....Q",".Q...","...Q."] is one) Example 2:
Input:
n = 1Output:
[["Q"]]Hints
1234567