Skip to content
Decoder

Sudoku Solver

Hard

Problem

Write a function that solves a Sudoku puzzle by filling the board in place. The board is a 9 by 9 list of lists of single-character strings: digits "1" to "9", and "." for an empty cell. When you finish:

- each row, each column, and each of the nine 3 by 3 boxes contains the digits 1 to 9 exactly once, and - every digit that was given at the start is unchanged.

The function is solve_sudoku(board) (Python) / solveSudoku(board) (TypeScript). It returns nothing; the tests read the board after the call.

Example 1

before (row 0):  ["5", "3", ".", ".", "7", ".", ".", ".", "."]

Example 2

after  (row 0):  ["5", "3", "4", "6", "7", "8", "9", "1", "2"]

Constraints

  • board.length == 9 and board[i].length == 9
  • board[i][j] is a digit 1 to 9 or '.'.
  • The puzzle has exactly one solution.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.