Back to DSA sheet
Valid Sudoku
MediumArraysA 9x9 Sudoku board is partially filled (empty cells are '.'). Validate that no row, column, or 3x3 box has a repeated digit 1-9. Only filled cells are checked; the board need not be solvable.
Input format (stdin): nine lines, each nine characters from '1'-'9' or '.'. Output true or false.
Examples
Input: 53..7....
6..195...
.98....6.
8...6...3
4..8.3..1
7...2...6
.6....28.
...419..5
....8..79
Output: true
No row, column, or box repeats a digit.
Constraints
- Board is 9x9
- cells are '1'-'9' or '.'
Sheets
NeetCode 150NeetCode 250
valid-sudoku.cpp2 sample tests
Loading editor
Test results
Run the sample tests to check your solution against expected output.
Custom input (stdin)
Output
Run your code to see its output.