Validate Sudoku

MATRIX
VALIDATION

Problem

Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:

  1. Each row must contain the digits 1-9 without repetition.
  2. Each column must contain the digits 1-9 without repetition.
  3. Each of the nine 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition.

A Sudoku board (partially filled) could be valid but is not necessarily solvable. Only the filled cells need to be validated.

Examples

isValidSudoku([ [5,3,0,0,7,0,0,0,0], [6,0,0,1,9,5,0,0,0], [0,9,8,0,0,0,0,6,0], [8,0,0,0,6,0,0,0,3], [4,0,0,8,0,3,0,0,1], [7,0,0,0,2,0,0,0,6], [0,6,0,0,0,0,2,8,0], [0,0,0,4,1,9,0,0,5], [0,0,0,0,8,0,0,7,9] ]); // true isValidSudoku([ [5,3,0,0,7,0,0,0,0], [6,0,0,1,9,5,0,0,0], [0,9,8,0,0,0,0,6,0], [8,5,0,0,6,0,0,0,3], [4,0,0,8,0,3,0,0,1], [7,0,0,0,2,0,0,0,6], [0,6,0,0,0,0,2,8,0], [0,0,0,4,1,9,0,0,5], [5,0,0,0,8,0,0,7,9] ]); // false (duplicate '5' in first column)
Loading...
5
3
0
0
7
0
0
0
0
6
0
0
1
9
5
0
0
0
0
9
8
0
0
0
0
6
0
8
0
0
0
6
0
0
0
3
4
0
0
8
0
3
0
0
1
7
0
0
0
2
0
0
0
6
0
6
0
0
0
0
2
8
0
0
0
0
4
1
9
0
0
5
0
0
0
0
8
0
0
7
9