Solve a Microsoft Sudoku Puzzle With Constraint-Guided Backtracking
Last updated: November 29, 2026
Quick Overview
Fill a partially completed 9x9 Sudoku grid in place so every row, column and 3x3 box contains the digits 1 to 9 exactly once, assuming the puzzle has a solution.
Microsoft
November 29, 20260
0
0 solved
Fill a partially completed 9x9 Sudoku grid in place so every row, column and 3x3 box contains the digits 1 to 9 exactly once, assuming the puzzle has a solution.
An onsite question that fits Microsoft's casual games (Microsoft Sudoku ships with Windows), used to see whether a candidate goes beyond naive cell-by-cell backtracking. Strong answers track constraints with bitmasks and choose the most constrained cell first, which turns hard puzzles from seconds into milliseconds.
What the Interviewer Expects
- Track used digits per row, column and box, ideally as bitmasks
- Pick the empty cell with the fewest candidates next (MRV heuristic)
- Fail fast when any cell has zero candidates
- Undo every change on backtrack
- Verify the solution or reason about correctness
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you check whether a puzzle has a unique solution?
- How would you generate new puzzles of a target difficulty for the game?
- How does this relate to exact cover and Dancing Links?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input is a 9x9 list of lists of characters, digits 1 to 9 or . for empty. Modify it in place into a valid solution. Givens must not change. Assume at least one solution exists; return True on su...
High-Level Design
Plain backtracking that fills cells in reading order works on easy puzzles but explores huge trees on hard ones. Two upgrades fix that. First, keep a 9-bit mask of used digits for each row, column and...