← Openai Interview Insights

Openai·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Apr 2026

Summary

Interviewed for an ML Engineer role at OpenAI and got a simulation-style coding problem that felt more like a grid puzzle than anything ML-specific. Short session, one meaty question.

Questions Asked (1)

Q1

Given a grid where infected cells spread each day and recover after D days (becoming immune), return the number of days until the grid fully stabilizes with no remaining infected cells.

Algorithms & Data Structures
Author's notes

Took me a minute to figure out what 'stabilizes' actually meant since immune cells block further spread.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a multi-source BFS where each infected cell has a state (infection day, recovery day) and spreads to neighbors daily. Simulate day by day, tracking active infections and immunity, until no infected cells remain; return the total days elapsed. Clarify edge cases like initial immunity, simultaneous recovery and spread, and grid boundaries.

Pro tip: Explicitly state your assumptions about the spread and recovery order (e.g., recovery happens before spread each day) and mention that you'd validate with small test cases to avoid off-by-one errors.

1. Clarify rules and edge cases

Ask about initial grid state (infected, healthy, immune), spread direction (4 or 8 neighbors), and whether recovery happens before or after spread on a given day. Confirm what 'fully stabilizes' means (no infected cells).

2. Choose data structures and state representation

Use a queue for BFS or a set of active infections. Track for each cell its infection day and recovery day, or maintain day counters. Consider using a 2D array for grid states and a queue for newly infected cells.

3. Simulate day by day

At each day, process recoveries (remove cells whose recovery day is today), then spread from currently infected cells to healthy neighbors, marking them infected with recovery day = current day + D. Increment day counter.

4. Terminate and return days

Stop when there are no infected cells (active or newly infected). Return the number of days elapsed. Handle the case where the grid starts with no infections (return 0).

5. Analyze complexity and optimize

Discuss time complexity O(N*M*D) in worst case if simulating day by day, but can be optimized to O(N*M) using BFS with time stamps. Mention space complexity O(N*M).

Key Points to Mention

  • Multi-source BFS or simulation approach
  • State tracking: infection day, recovery day, immunity
  • Order of operations: recovery before spread (or clarify)
  • Edge cases: no initial infections, all immune, grid boundaries
  • Time and space complexity analysis
  • Potential optimization: BFS with time stamps instead of day-by-day simulation

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