51. N Queens
Practice N Queens for free on NudgeCode: Hard, Backtracking pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Place n queens on an n x n chess board so that no two queens share a row, a column or a diagonal. Return every such board. Each board is a list of n strings, one per row from top to bottom, with 'Q' for a queen and '.' for an empty square. The boards can be in any order.
Example
n = 4 -> [[".Q..","...Q","Q...","..Q."],
["..Q.","Q...","...Q",".Q.."]]
Constraints
- 1 <= n <= 8