Validate a Sudoku Board
Updated
Problem statement
Given a partially filled 9 x 9 Sudoku board, return true if every filled cell obeys the Sudoku rules and false otherwise.
Each row, each column, and each of the nine 3 x 3 sub-boxes may contain each digit from 1 through 9 at most once. An empty cell contains '.'.
Check only whether the filled cells are consistent. The board does not need to be solvable.
Function
isValidSudoku(board: char[][]) → booleanExamples
Example 1
board = [["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"]]return = trueNo row, column, or sub-box repeats a filled digit.
Example 2
board = [["5","3",".",".","7",".",".",".","5"],["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"]]return = falseThe first row contains digit 5 twice.
Constraints
board.length == 9.board[i].length == 9.- Every cell is
'.'or a digit from'1'through'9'.
More ZipRecruiter Onsite Interview questions
- Restaurant Vote LeadersPHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2026
- Sliding Window Rate LimiterOA · ONSITE INTERVIEW · Seen Oct 2022
- Sort an Integer Array in Ascending OrderOA · ONSITE INTERVIEW · Seen Apr 2022
- Classify an Alien Dictionary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2022
- Add Numbers Stored in Four-Digit ChunksONSITE INTERVIEW · Seen Nov 2021
- Add Two Numeric Strings with CarryONSITE INTERVIEW · Seen Nov 2021
- Expand Decimal Digits into Runs of OnesONSITE INTERVIEW · Seen Nov 2021
- Solve a Sudoku BoardONSITE INTERVIEW · Seen Aug 2021
- Iterate Ragged Integer Lists VerticallyONSITE INTERVIEW · Seen May 2017
- Min StackONSITE INTERVIEW · Seen Feb 2017
Similar questions at other companies
- Sudoku Board ValidationConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
- Validate Rectangular Game PiecesGoogle · ONSITE INTERVIEWGoogle interview questions
- Set Matrix ZeroesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Query Whether an Island Size ExistsMeta · ONSITE INTERVIEWMeta interview questions
- Check a Partly Filled Sudoku GridExpedia · ONSITE INTERVIEWExpedia interview questions
- Cache Shared Image Pipeline PrefixesAnthropic · ONSITE INTERVIEWAnthropic interview questions
- Number of Submatrices That Sum to TargetWhatNot · ONSITE INTERVIEWWhatNot interview questions
- Sparse Matrix MultiplicationByteDance · PHONE SCREENByteDance interview questions
- First Completed Mingo LineEpic · OAEpic interview questions
- Valid SudokuVerkada · PHONE SCREENVerkada interview questions