hard

N-Queens

Place n queens on an n × n chessboard so that no two queens attack each other (share a row, column or diagonal). Return every distinct arrangement as a list of board rows.

Constraints
  • 1 ≤ n ≤ 9
Examples
in: n = 4
out: [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]

Code it yourself

Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?

Choose an approach to check your pattern recognition, or reveal the discussion when you need help.