← Pinterest Interview Insights

Pinterest·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
May 2026

Summary

Pinterest ML Engineer interview that came down to a classic backtracking puzzle. Nothing flashy, just grind through the board and hope your constraint logic doesn't blow up.

Questions Asked (1)

Q1

Given a partially filled 9x9 Sudoku board, write a function to fill in the empty cells so the completed board is valid (each row, column, and 3x3 box contains digits 1 through 9 with no repeats).

Algorithms & Data Structures
Author's notes

Backtracking was the obvious move but I spent probably too long trying to be clever about constraint propagation before just committing to the recursive approach.

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 each empty cell, checking validity against row, column, and box constraints, and backtrack when no valid digit fits. Optimize by selecting the empty cell with the fewest candidates (MRV heuristic) and using bitmasks to track used digits for O(1) validity checks.

Pro tip: Mention that while backtracking is standard, for production systems you might use a constraint satisfaction solver or exact cover (Dancing Links) for guaranteed performance, and always discuss time/space complexity and potential optimizations.

1. Clarify requirements and constraints

Confirm that the input is a 9x9 grid with digits 1-9 and empty cells represented by '.' or 0, and that a solution is guaranteed to exist. Discuss whether to modify in-place or return a new board.

2. Choose an algorithm

Select backtracking as the base algorithm, and explain how to incorporate heuristics like Minimum Remaining Values (MRV) and bitmasking for efficiency. Mention alternative approaches like exact cover if relevant.

3. Implement validity checks

Design helper functions to check if placing a digit is valid by ensuring no duplicates in the current row, column, and 3x3 sub-box. Use arrays or bitmasks to track used digits for O(1) checks.

4. Implement recursive backtracking

Write a recursive function that finds the next empty cell (preferably with MRV), tries digits 1-9, and recurses if valid. If no digit works, backtrack by resetting the cell and returning false.

5. Analyze complexity and test

Discuss time complexity (worst-case exponential but typically fast for 9x9) and space complexity (O(1) extra space). Walk through a small example or edge cases like an already solved board.

Key Points to Mention

  • Backtracking algorithm with recursion
  • Constraint propagation using row, column, and box sets
  • Heuristic: Minimum Remaining Values (MRV) for cell selection
  • Bitmasking for efficient validity checks
  • Time and space complexity analysis
  • Alternative approaches like exact cover (Dancing Links) for optimization

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