N-Queens
Place n queens on an n x n chessboard so that no two attack each other (no shared row, column, or diagonal). Return all distinct board configurations, each drawn as a list of strings using 'Q' for a queen and '.' for empty.
Open official problem prompt ↗Enumerate every arrangement of n mutually non-attacking queens, rendered as string boards.
Seating n guests who each refuse to share a row, column, or diagonal sightline; you seat one per row and back out the instant the next row has no free seat.
- Input
- n = 4
- Output
- [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
- Why
- These are the only two ways to place 4 non-attacking queens; in each, every row, column, and both diagonal directions hold at most one queen.
1 <= n <= 9