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.
Example 1
Input: n = 4
Output: [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
Explanation: On a 4 x 4 board there are exactly two ways to place 4 queens so that no two share a row, column or diagonal. One is the mirror image of the other.
Example 2
Input: n = 1
Output: [["Q"]]
Explanation: A 1 x 1 board holds one queen, which has nothing to attack.
Example 3
Input: n = 2
Output: []
Explanation: On a 2 x 2 board, any two queens share a row, a column or a diagonal, so there is no solution.
Place exactly one queen per row. A column is safe if that column and both of its diagonals are unoccupied, checkable in O(1) with three sets.
Run checks all cases above. Submit evaluates all test cases.