Sudoku Validator - Problem
A Sudoku puzzle is a 9×9 grid filled with digits 1-9. A valid Sudoku has the following properties:
- Each row contains the digits 1-9 without repetition
- Each column contains the digits 1-9 without repetition
- Each of the nine 3×3 sub-boxes contains the digits 1-9 without repetition
Given a completed 9×9 Sudoku board, determine if it is valid.
Note: The input will always be a complete 9×9 grid with digits 1-9 only (no empty cells).
Input & Output
Example 1 — Valid Sudoku
$
Input:
board = [[5,3,4,6,7,8,9,1,2],[6,7,2,1,9,5,3,4,8],[1,9,8,3,4,2,5,6,7],[8,5,9,7,6,1,4,2,3],[4,2,6,8,5,3,7,9,1],[7,1,3,9,2,4,8,5,6],[9,6,1,5,3,7,2,8,4],[2,8,7,4,1,9,6,3,5],[3,4,5,2,8,6,1,7,9]]
›
Output:
true
💡 Note:
This is a valid completed Sudoku. Each row, column, and 3×3 box contains all digits 1-9 exactly once.
Example 2 — Invalid Row
$
Input:
board = [[5,3,5,6,7,8,9,1,2],[6,7,2,1,9,5,3,4,8],[1,9,8,3,4,2,5,6,7],[8,5,9,7,6,1,4,2,3],[4,2,6,8,5,3,7,9,1],[7,1,3,9,2,4,8,5,6],[9,6,1,5,3,7,2,8,4],[2,8,7,4,1,9,6,3,5],[3,4,5,2,8,6,1,7,9]]
›
Output:
false
💡 Note:
The first row has two 5s at positions 0 and 2, making it invalid.
Example 3 — Invalid Box
$
Input:
board = [[5,3,4,6,7,8,9,1,2],[6,7,2,1,9,5,3,4,8],[1,9,5,3,4,2,5,6,7],[8,5,9,7,6,1,4,2,3],[4,2,6,8,5,3,7,9,1],[7,1,3,9,2,4,8,5,6],[9,6,1,5,3,7,2,8,4],[2,8,7,4,1,9,6,3,5],[3,4,5,2,8,6,1,7,9]]
›
Output:
false
💡 Note:
The top-left 3×3 box contains two 5s, violating the Sudoku rules.
Constraints
- board.length == 9
- board[i].length == 9
- 1 ≤ board[i][j] ≤ 9
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code