Valid Sudoku
Check the filled cells of a 9 by 9 Sudoku board. Each row, column and aligned 3 by 3 box must have no repeated digit. Dots are empty; you need not determine whether the board is solvable.
Example 1
board = [["4",".",".",".",".",".",".",".","."],[".","7",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."]]trueExplanation
4 and 7 have different rows and columns and are different digits within their box.
Example 2
board = [["4",".",".",".",".",".",".",".","4"],[".","7",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."]]falseExplanation
Row 0 repeats 4 at columns 0 and 8.
Example 3
board = [["4",".",".",".",".",".",".",".","."],[".","7",".",".",".",".",".",".","."],[".",".","4",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."]]falseExplanation
The top-left box repeats 4 at (0,0) and (2,2), despite different rows and columns.
Constraints
- Board is exactly 9 by 9
- Cells are dots or digits 1..9
Function contract
isValidSudokuArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[["4",".",".",".",".",".",".",".","."],[".","7",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."]]