Solve a Sudoku Board
Updated
Problem statement
Given a partially filled 9 x 9 Sudoku board, fill every empty cell so that the completed board is valid.
Each row, each column, and each of the nine 3 x 3 sub-boxes must contain the digits 1 through 9 exactly once. An empty cell contains '.'.
The given clues are valid, and the board has exactly one solution. Return the completed board.
Function
solveSudoku(board: char[][]) → char[][]Examples
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 = [["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"]]Moved or new
The filled board contains every digit exactly once in each row, column, and sub-box.
Example 2
board = [[".","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","."]]return = [["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"]]Moved or new
The two missing corner values are forced by their rows and columns.
Constraints
board.length == 9.board[i].length == 9.- Every cell is
'.'or a digit from'1'through'9'. - The given clues obey the Sudoku rules.
- The board has exactly one solution.
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
- Validate 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 Puzzle SolverConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
- Sudoku SolverNutanix · ONSITE INTERVIEWNutanix interview questions
- Sudoku SolverInMobi · PHONE SCREENInMobi interview questions
- Sparse Plant Infection SimulationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Word Search IIAmazon · ONSITE INTERVIEW
- Rectangular K-in-a-RowDatabricks · ONSITE INTERVIEWDatabricks interview questions
- Optimal Account BalancingPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
- Partition a Card Deck into FifteensMeta · ONSITE INTERVIEWMeta interview questions
- Cache Shared Image Pipeline PrefixesAnthropic · ONSITE INTERVIEWAnthropic interview questions
- Place K Buildings to Minimize Maximum Grid DistanceOracle · ONSITE INTERVIEWOracle interview questions