What you're building
A validateSudoku(board) function that checks whether a partially-filled 9×9 Sudoku board is valid.
The board is a 9-element array of 9-element arrays. Each cell is either a digit 1–9 (number) or 0 meaning empty.
validateSudoku([
[5,3,0, 0,7,0, 0,0,0],
[6,0,0, 1,9,5, 0,0,0],
// ... 7 more rows
]); // true or false
Requirements
- Return
trueif the current (possibly partial) board state is valid. - Return
falseif any row, column, or 3×3 box contains a duplicate non-zero digit. - Empty cells (value
0) are ignored — they don't cause a violation on their own. - Do not require the board to be fully solved — just validate what is filled in.
Stretch goals
- Return a list of all violations (e.g.
"row 2 has duplicate 5") instead of a boolean. - Write a Sudoku solver that uses backtracking on top of this validator.
- Generate a random valid partially-filled puzzle.
What this proves
This problem is a favourite at FAANG-level interviews. It cleanly exercises 2-D array traversal, modular indexing for the 3×3 boxes, and the "use a Set to detect duplicates" pattern — skills that transfer directly to matrix and grid problems across interviews.
⚡ 40 XP
solution.jsRuns in your browser
Loading editor…
Tests4 to pass
valid partial board
detects duplicate in row
detects duplicate in column
detects duplicate in 3x3 box
Run your code to check these.