N-Queens Completion
HardP3Coding
board is an n x n chessboard given as n strings. 'Q' marks a queen that is already placed and cannot be moved, and '.' marks an empty cell.
Return true if you can add queens to empty cells so that the board ends up with exactly n queens and no two attack each other (no shared row, column or diagonal). Return false if the queens already on the board attack each other, or if no completion exists.
Example 1
- Input
- board = ["....","....","....","...."]
- Output
- true
Example 2
- Input
- board = [".Q..","....","....","...."]
- Output
- true
Example 3
- Input
- board = ["Q...",".Q..","....","...."]
- Output
- false
Constraints
- 1 <= n <= 10
board[i][j]is'Q'or'.'
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 11. ⌘Enter runs, ⌘⇧Enter submits.