hardBacktrackingPure DSA~45 min
Shift Grid Constraint Solver
A 9×9 staffing grid must be filled so each row, each column, and each 3×3 zone contains the digits 1–9 exactly once (a Sudoku). Some cells are pre-assigned; fill the rest.
Problem
Solve a partially filled 9×9 Sudoku board in place. Empty cells are '.'. Each row, column, and 3×3 sub-box must contain digits 1–9 exactly once. A valid solution is guaranteed to exist and be unique.
Input
A 9×9 grid of characters, each '1'–'9' or '.'.
Output
The same grid mutated in place so every '.' is replaced by a valid digit.
Constraints
- Board is always 9×9
- Given clues are valid and the puzzle has exactly one solution
- Mutate the board in place
Examples
Example 1
Input
A standard puzzle with ~30 clues filled and the rest '.'
Output
The uniquely completed grid
Backtracking tries digits in each empty cell, abandoning any that violate a constraint.
Example 2
Input
A near-complete board with a single empty cell
Output
The board with that cell filled by the only legal digit
Constraint checks immediately fix the forced value.