← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Google SWE interview with a classic backtracking problem. Nothing too surprising but the in-place constraint is the kind of detail that trips you up if you're not paying attention.

Questions Asked (1)

Q1

Write a program that solves a Sudoku puzzle by filling in the empty cells in-place, following the standard rules: each digit 1-9 appears exactly once per row, column, and 3x3 box.

Algorithms & Data Structures
Author's notes

The core of this is backtracking and I knew that going in, but I fumbled the box index calculation for a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use backtracking with constraint propagation: recursively try digits 1-9 in empty cells, checking validity against row, column, and box constraints. Optimize by choosing the cell with the fewest candidates (MRV heuristic) and using bitmasks for O(1) validity checks.

Pro tip: Mention that while backtracking is standard, you can discuss advanced optimizations like Dancing Links (Algorithm X) for exact cover problems, showing depth beyond the expected solution.

1. Clarify requirements and constraints

Confirm that the input is a 9x9 grid with some cells pre-filled, and the goal is to fill all empty cells in-place. Ask about assumptions like guaranteed solvability and whether to modify the input or return a new grid.

2. Choose the algorithm

Select backtracking as the core approach, and decide on optimizations such as MRV heuristic and bitmasking for constraint checks. Explain why backtracking is suitable for this constraint satisfaction problem.

3. Implement the solution

Write a recursive function that finds the next empty cell, tries digits 1-9, and backtracks if a digit leads to an invalid state. Use helper functions to check row, column, and box validity efficiently.

4. Optimize and analyze complexity

Discuss time and space complexity: worst-case O(9^(n*n)) but with pruning it's much faster. Mention how MRV and bitmasks reduce the search space and improve performance.

5. Test and handle edge cases

Walk through a simple example to verify correctness. Consider edge cases like already solved puzzles, invalid inputs, and multiple solutions (though standard Sudoku has a unique solution).

Key Points to Mention

  • Backtracking algorithm with recursion
  • Constraint checking for rows, columns, and 3x3 boxes
  • Optimization using bitmasks for O(1) validity checks
  • Minimum Remaining Values (MRV) heuristic to choose next cell
  • Time complexity analysis and pruning benefits
  • Alternative approaches like Dancing Links (Algorithm X) for exact cover

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.