Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

107. Sudoku Solver

HardDay 32 of 60Recursion & Backtracking

Fill in a partially completed 9 x 9 Sudoku board so that every row, every column and every 3 x 3 box contains each digit from 1 to 9 exactly once. Empty cells are shown as ".". Modify board in place; the method returns nothing. The input is guaranteed to have a solution.

Example 1
Input: board = [["5","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".",".","."], ... ]
Output: [["5","3","4","6","7","8","9","1","2"],["6","7","2","1","9","5","3","4","8"], ... ]
Each "." is replaced by the only digit that keeps all rows, columns and boxes valid.
Constraints
  • board.length == 9 and board[i].length == 9
  • board[i][j] is a digit 1 to 9 or "."
  • The puzzle has at least one solution
Hints
Frequently asked at: Amazon, Microsoft, Uber, Samsung
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min