#K76777. Valid Sudoku Checker
Valid Sudoku Checker
Valid Sudoku Checker
You are given a 9×9 Sudoku grid where each cell contains a digit from '1' to '9' or a dot ('.') representing an empty cell. Your task is to check whether the given grid is a valid Sudoku solution. A valid Sudoku grid must satisfy the following constraints:
-
Each row must contain the digits from 1 to 9 without repetition. That is, for every row ( i ), the set of non-empty entries satisfies [ |{ grid[i][j] : grid[i][j] \neq '.' }| = \text{number of non-empty cells in row } i. ]
-
Each column must contain the digits from 1 to 9 without repetition. For every column ( j ), [ |{ grid[i][j] : grid[i][j] \neq '.' }| = \text{number of non-empty cells in column } j. ]
-
Each of the nine 3×3 sub-grids must also contain the digits 1 to 9 without repetition. For every sub-grid starting at ( (i,j) ) where ( i,j \in {0,3,6} ), [ |{ grid[x][y] : x \in [i,i+3),; y \in [j,j+3) \text{ and } grid[x][y] \neq '.' }| = \text{number of non-empty cells in the sub-grid}. ]
Input is provided via standard input (stdin) and output should be printed to standard output (stdout). Print "True" if the grid is a valid Sudoku solution, otherwise print "False".
inputFormat
The input consists of 9 lines, each containing 9 space-separated characters. Each character is either a digit (from '1' to '9') or a dot ('.') indicating an empty cell.
outputFormat
Output a single line with either "True" or "False" indicating whether the provided Sudoku grid is valid.## sample
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