Sudoku Solver
Fill a partially completed 9x9 Sudoku board in place so that every row, every column, and each of the nine 3x3 sub-boxes contains the digits 1-9 exactly once. Empty cells are marked with '.'; a unique solution is guaranteed.
Open official problem prompt ↗Complete the grid so all Sudoku rules hold, mutating the given board in place.
Like solving a crossword in pen you can erase: pencil in a letter that fits every crossing word, keep going, and rub it out the moment a later square has no legal option.
- Input
- board = [["5","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".",".","."],[".","9","8",".",".",".",".","6","."],["8",".",".",".","6",".",".",".","3"],["4",".",".","8",".","3",".",".","1"],["7",".",".",".","2",".",".",".","6"],[".","6",".",".",".",".","2","8","."],[".",".",".","4","1","9",".",".","5"],[".",".",".",".","8",".",".","7","9"]]
- Output
- First row becomes ["5","3","4","6","7","8","9","1","2"] and the whole board is fully and validly filled.
- Why
- Every row, column, and 3x3 box now holds 1-9 once; the given clues are unchanged.
board.length == 9board[i].length == 9board[i][j] is a digit 1-9 or '.'It is guaranteed that the input board has exactly one solution