Lessons learned: HashMaps, iterations
|Sameer Khoja||Nov 5|
Determine if a 9x9 sudoku board is valid. Only the filled cells need to be validated according to the following rules:
Each row must contain the digits 1-9 without repetition
Each column must contain the digits 1-9 without repetition
Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.
Note: A Sudoku board can be filled but is not necessarily solvable. Only the filled cells need to be validated according to the mentioned rules.
An easy approach to solving this problem is to contain maps of what we have seen so far in rows, columns, and boxes. Then we count the number of times we see the current number in that specific row, column, and box index. Lastly, if the counts of any of these instances is more than 1, we can return false because it violates any one of the above conditions.
The below methods implements the described approach: