Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Valid Sudoku

XPChallenge Points: 20
levelLevel: Medium

Check if a 9 x 9 Sudoku board is valid. Only the filled cells need to follow these rules:
1. Each row must contain digits 1-9 without duplicates.
2. Each column must contain digits 1-9 without duplicates.
3. Each 3 x 3 sub-grid must contain digits 1-9 without duplicates.
Note: The board may be partially filled. You only need to check for validity, not solve the puzzle.


Example 1:

Input: board = [ ["6","1",".",".","7",".",".",".","."], ["2",".",".","8","4","9",".",".","."], [".","5","3",".",".",".",".","2","."], [".",".",".",".","6",".",".",".","1"], ["3",".",".","2",".","7",".",".","5"], [".",".",".",".","9",".",".",".","4"], [".","2",".",".",".",".","5","3","."], [".",".",".","6","1","8",".",".","2"], [".",".",".",".","5",".",".","7","6"] ]

Output: true

Example 2:

Input: board = [ ["7","1",".",".","7",".",".",".","."], ["2",".",".","8","4","9",".",".","."], [".","5","3",".",".",".",".","2","."], [".",".",".",".","6",".",".",".","1"], ["3",".",".","2",".","7",".",".","5"], [".",".",".",".","9",".",".",".","4"], [".","2",".",".",".",".","5","3","."], [".",".",".","6","1","8",".",".","2"], [".",".",".",".","5",".",".","7","6"] ]

Output: false

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result