Solve a Sudoku Puzzle for a Daily Puzzle Feature
Last updated: November 29, 2026
Quick Overview
Fill a 9 by 9 Sudoku grid in place so every row, column, and 3 by 3 box contains digits 1 to 9 exactly once. Empty cells are marked with a dot and the puzzle has at least one solution.
0
0
0 solved
Fill a 9 by 9 Sudoku grid in place so every row, column, and 3 by 3 box contains digits 1 to 9 exactly once. Empty cells are marked with a dot and the puzzle has at least one solution.
A Google onsite problem framed as the solver behind a daily puzzle card in a Google app. Beyond correct backtracking, the interviewer looks for constant-time validity checks with bitmasks and the most-constrained-cell heuristic that makes hard puzzles fast.
What the Interviewer Expects
- Maintains row, column, and box usage so each check is O(1)
- Backtracks by undoing both the grid write and the usage bookkeeping
- Chooses the empty cell with the fewest candidates first (MRV)
- Explains why MRV collapses the search on typical puzzles
- Returns a success flag so recursion stops at the first solution
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 that a puzzle has a unique solution?
- How would you generate a new puzzle with a unique solution and a target difficulty?
- How would you extend this to 16 by 16 grids?
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: 9x9 list of lists of characters
'1'..'9'or'.'. - Output: the board filled in place. Assume at least one solution exists; return True if solved.
- Runtime should be fast even on hard puz...
High-Level Design
Bookkeeping: three arrays of 9-bit masks, rows[r], cols[c], boxes[b] with b = (r // 3) * 3 + c // 3. Bit d - 1 set means digit d is used. The candidates for cell (r, c) are `~(rows[r] | cols[c...