#C2411. Valid Sudoku Checker
Valid Sudoku Checker
Valid Sudoku Checker
You are given a 9x9 Sudoku board. The board is partially filled, where empty cells are represented by a dot .
. Your task is to determine if the board is valid 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 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition.
Note that the board only needs to be valid according to the above rules and does not need to be solvable. In other words, you only need to verify that no rule is broken.
The validity criteria can be expressed mathematically as:
\(\forall i \in \{0,\dots,8\},\; \{a_{i0},a_{i1},\dots,a_{i8}\} \text{ contains no duplicate digits (ignoring dots)}\)
and similarly for columns and 3x3 sub-boxes.
inputFormat
The input consists of 9 lines, each line contains 9 space-separated characters. Each character is either a digit ('1'-'9') or a dot '.' representing an empty cell.
outputFormat
Output a single line containing either True
if the provided Sudoku board is valid, or False
if it is not.
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
True