Ever wondered how those classic number puzzle games validate their boards? Welcome to the world of Sudoku validation!
You're given a 9 ร 9 Sudoku board that may be partially filled. Your mission is to determine whether the current state follows all Sudoku rules - but here's the catch: you only need to validate the filled cells, not solve the entire puzzle.
The Three Sacred Rules of Sudoku:
- ๐ด Each row must contain digits 1-9 without repetition
- ๐ต Each column must contain digits 1-9 without repetition
- ๐ข Each 3ร3 sub-box must contain digits 1-9 without repetition
Empty cells are represented by '.' and should be ignored during validation. A valid board doesn't need to be solvable - it just needs to follow the rules for existing numbers.
Input: A 9ร9 matrix representing the Sudoku board
Output: true if valid, false if any rule is violated
Input & Output
Visualization
Time & Space Complexity
Single pass through fixed 9ร9 board with constant time hash set operations. In general case, O(nยฒ) where n is board dimension.
Fixed space for 27 hash sets (9 rows + 9 columns + 9 boxes), each storing at most 9 digits
Constraints
-
board.length == 9 -
board[i].length == 9 -
board[i][j]is a digit1-9or'.' - Only filled cells need to be validated