Skip to content
Onsite

N-Queens

HardP2Coding

Place n queens on an n x n chessboard so that no two attack each other (no two share a row, column or diagonal). Return every distinct arrangement, in any order.

Each arrangement is an array of n strings, one per row, with 'Q' where a queen sits and '.' for an empty square.

Example 1

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

Example 2

Input
n = 2
Output
[]

Example 3

Input
n = 3
Output
[]

Constraints

  • 1 <= n <= 9

Hints

Run checks the 3 visible tests, Submit all 9.