You are given a 9x9 2D array of integers, which represents a solved Sudoku board. Each cell board[i][j] within this array contains a single digit from 1 to 9.
Your task is to determine if this solved Sudoku board is indeed valid according to the classic Sudoku rules.
Remember that a Sudoku board is valid if:
1-9 without repetition.1-9 without repetition.3x3 sub-boxes of the grid must contain the digits 1-9 without repetition.Return true if the Sudoku board is valid, false otherwise.
[ [1, 2, 3, 4, 5, 6, 7, 8, 9], [4, 5, 6, 7, 8, 9, 1, 2, 3], [7, 8, 9, 1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7, 8, 9, 1], [5, 6, 7, 8, 9, 1, 2, 3, 4], [8, 9, 1, 2, 3, 4, 5, 6, 7], [3, 4, 5, 6, 7, 8, 9, 1, 2], [6, 7, 8, 9, 1, 2, 3, 4, 5], [9, 1, 2, 3, 4, 5, 6, 7, 8] ]
True
This board is a perfectly solved and valid Sudoku board. All rows, columns, and 3x3 subgrids contain digits 1-9 exactly once.
[ [1, 2, 3, 4, 5, 6, 7, 8, 9], [4, 5, 6, 7, 8, 9, 1, 2, 3], [2, 3, 4, 5, 6, 7, 8, 9, 1], [7, 8, 9, 1, 2, 3, 4, 5, 6], [5, 6, 7, 8, 9, 1, 2, 3, 4], [8, 9, 1, 2, 3, 4, 5, 6, 7], [3, 4, 5, 6, 7, 8, 9, 1, 2], [6, 7, 8, 9, 1, 2, 3, 4, 5], [9, 1, 2, 3, 4, 5, 6, 7, 8] ]
False
This board is invalid because 2 appears in the 3x3 sub-box starting at (0,0) twice, violating the Sudoku rule that each number must appear exactly once per sub-box.
[ [1, 2, 3, 4, 5, 6, 7, 8, 9], [4, 5, 6, 7, 8, 9, 1, 2, 3], [2, 3, 4, 5, 6, 7, 8, 9, 1], [7, 8, 9, 1, 2, 3, 4, 5, 6], [5, 6, 7, 8, 9, 1, 2, 3, 4], [8, 9, 1, 2, 3, 4, 5, 6, 7], [3, 4, 5, 6, 7, 8, 9, 1, 2], [6, 7, 8, 9, 1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 7, 8, 9] ]
False
This board is invalid because 1 appears twice in the first column, violating the Sudoku rule that each number must appear exactly once per column.
[ [1, 2, 3, 4, 5, 6, 7, 8, 9], [4, 5, 6, 7, 8, 9, 1, 2, 3], [7, 8, 9, 1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7, 8, 9, 1], [5, 6, 7, 8, 9, 1, 2, 3, 4], [8, 9, 1, 2, 3, 4, 5, 6, 7], [3, 4, 5, 6, 7, 8, 9, 1, 2], [6, 7, 8, 9, 1, 2, 3, 4, 5], [9, 1, 2, 3, 4, 5, 6, 7, 8] ]
True