Valid Sudoku
You are given a partially filled 9 x 9 Sudoku board as a grid of strings. Each cell is either a digit "1" to "9" or "." for an empty cell. Return true if the board is valid so far, meaning:
- each row contains no digit more than once,
- each column contains no digit more than once,
- each of the nine
3 x 3boxes (the ones that start at rows and columns 0, 3 and 6) contains no digit more than once.
Only the filled cells are checked. A valid board does not have to be solvable.
Constraints
- The board has exactly 9 rows and 9 columns.
- Every cell is
"."or a digit from"1"to"9".
Examples
Example 1
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: true
The well-known partial puzzle breaks no row, column or box rule. It does not need to be solvable, only consistent.
Example 2
Input: board = [["8","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: false
Putting an 8 in the top-left corner repeats the 8 of row 3 in the same column, and the 8 in row 2 in the same box.
Example 3
Input: board = [["5",".",".",".",".",".",".",".","."],[".","3",".",".",".",".",".",".","."],[".",".","5",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."]] Output: false
No row or column repeats, but both 5s sit in the top-left 3 x 3 box.
JavaScript you'll use: Map and Set Arrays: create, read, update
/**
* @param {string[][]} board
* @return {boolean}
*/
function isValidSudoku(board) {
}
Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.