Description

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. Each solution contains a distinct board configuration where 'Q' indicates a queen and '.' indicates an empty space.

Examples

Input:n = 4
Output:[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
Explanation:

There exist two distinct solutions to the 4-queens puzzle.

Input:n = 1
Output:[["Q"]]
Explanation:

Single queen on 1x1 board.

Input:n = 2
Output:[]
Explanation:

Edge case with empty result.

Constraints

  • 1 ≤ n ≤ 9

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!