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
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
backtracking
bitmasks
constraint propagation
MRV heuristic
search
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported