Sudoku Solver
HardP3Coding
board is a 9 x 9 Sudoku puzzle given as 9 strings of 9 characters. A digit 1-9 is a given, and . is an empty cell. Return the solved board in the same format.
A solution fills every empty cell so that each row, each column and each of the nine 3 x 3 boxes contains the digits 1 to 9 exactly once. Every puzzle in the tests has exactly one solution.
Example 1
- Input
- board = ["93...75.4","..5931.6.",".6742...9",".43.962.7",".96.82..5","7..5436..",".7.....1.","61827....","3.96184.2"]
- Output
- ["931867524","425931768","867425139","543196287","196782345","782543691","274359816","618274953","359618472"]
Example 2
- Input
- board = ["9.....52.",".2....7.8",".6..25...","5.319.2.7","1.67.....",".8.5....1","274.59..6",".18....5.","...6...7."]
- Output
- ["931867524","425931768","867425139","543196287","196782345","782543691","274359816","618274953","359618472"]
Example 3
- Input
- board = [".31......","4....1...","..7.25..9","5...9..87",".9..82...",".8....6.1",".743.....","6........",".5...8.7."]
- Output
- ["931867524","425931768","867425139","543196287","196782345","782543691","274359816","618274953","359618472"]
Constraints
- board has 9 strings of length 9
- Characters are
1-9or. - The puzzle has exactly one solution.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 6. ⌘Enter runs, ⌘⇧Enter submits.