Complete a Sudoku Board
Updated
Problem statement
Complete the 9 x 9 Sudoku board. A zero marks an unfilled cell; replace every zero with a digit from 1 through 9. Keep every original nonzero value unchanged.
The completed board must contain each digit from 1 through 9 exactly once in every row, every column and each of the nine aligned 3 x 3 boxes.
Return the completed matrix. Zeros mark blanks in the input. Each board has a unique solution.
Function
solveSudoku(board: int[][]) → int[][]Examples
Example 1
board = [[5,3,0,0,7,0,0,0,0],[6,0,0,1,9,5,0,0,0],[0,9,8,0,0,0,0,6,0],[8,0,0,0,6,0,0,0,3],[4,0,0,8,0,3,0,0,1],[7,0,0,0,2,0,0,0,6],[0,6,0,0,0,0,2,8,0],[0,0,0,4,1,9,0,0,5],[0,0,0,0,8,0,0,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
Fill the 51 blank cells while retaining all 30 givens. The returned board has each digit from 1 through 9 once in every row, column and aligned box.
Example 2
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],[0,0,0,0,0,0,0,0,0]]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 first eight rows are complete. Each column is missing exactly the digit shown in the last row of the returned board, so all nine blanks are forced.
Constraints
boardhas exactly9rows and exactly9columns in every row.0 <= board[r][c] <= 9; zero is a blank.- For this exercise, assume the nonzero givens are valid and the board has exactly one solution. Invalid or unsatisfiable boards are outside the input domain.
More JP Morgan Chase Online Assessment questions
- Find Total CostOA · Seen Oct 2026
- Minimum Meeting RoomsOA · Seen Oct 2026
- Count Dropped RequestsOA · Seen Oct 2026
- Maximize Minimum Deployment DifficultyOA · Seen Oct 2026
- Task SchedulingOA · Seen Oct 2026
- Substring RemovalOA · Seen Oct 2026
- Maximum Game Board ScoreOA · Seen Sep 2026
- Minimum Digit Changes Between String HalvesOA · Seen Sep 2026
- Same Substring Within BudgetOA · Seen Sep 2026
- Invert Ad Visibility BitsOA · Seen Aug 2026
Similar questions at other companies
- Empty ShelfSquarepoint Capital · OASquarepoint Capital interview questions
- Cave AdvantureMeta · OAMeta interview questions
- Optimal Office PlacementRoblox · OARoblox interview questions
- Word SearchBloomberg LP · OA · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Four-by-Four Boundary GridSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Rat in a Maze: All Simple PathsPeopleStrong · OAPeopleStrong interview questions
- Find a Word Path Moving Right or DownIntuit · OAIntuit interview questions
- Word Search IIAmazon · ONSITE INTERVIEW
- Sudoku Puzzle SolverConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
- Choose the Next Minesweeper ActionRunloop · PHONE SCREEN