N-Queens Problem

00:00
HardRecursionBacktracking
AmazonGoogle

Place n queens on an n×n chessboard so no two attack each other. Return all valid board configurations.

Examples

Input → n=4
Output → 2 solutions: ['.Q..','...Q','Q...','..Q.'] and ['..Q.','Q...','...Q','.Q..']
Input → n=1
Output → [['Q']]
Input → n=2 or n=3
Output → []
Note: no solution