Question
N-Queens Puzzle

The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.

Given an integer n, return all distinct solutions to the n-queens puzzle. You may return the answer in any order.

Each solution contains a distinct board configuration of the n-queens placement, where 'Q' and '.' both indicate a queen and an empty space, respectively.

Note:

  • A queen can attack horizontally, vertically, and diagonally. Therefore, no two queens should share the same row, column, or diagonal.
Input
User Task
As this is a functional problem, Your task here is to implement the function solveNQueens, which takes only an integer n as its argument, representing the size of the chessboard.


Custom Input
The first line of the input contains a single integer n, representing the dimensions of the chessboard.
Output
Return an array of array of strings representing all the possible ways to place the n Queens on the chessboard so that no two queens attack each other.

Custom Output
Print the whole combinations of n x n chess board (sorted-manner), where queens are placed without attacking each other, where combinations are separated via separator.
Example
Sample Input
4
Sample Output
-------------------
..Q.
Q...
...Q
.Q..
-------------------
.Q..
...Q
Q...
..Q.
-------------------
Explanation:
There exist two distinct solutions to the 4 queens puzzle as shown above

Online