69. N-Queens

Place n queens on an n × n chessboard so that no two attack each other (same row, column or diagonal). Return every distinct board, each as a list of strings where 'Q' is a queen and '.' is empty.

Example 1

Input: n = 4
Output: [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
Explanation: The two solutions for a 4×4 board.

Example 2

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

Place one queen per row.

Hint 2

Cells on the same diagonal share r − c; on the same anti-diagonal they share r + c.

Backtracking