← Openai Interview Insights

Openai·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
May 2026

Summary

Got a pretty gnarly coding question for an ML Engineer role at OpenAI, basically a heavily extended version of the classic rotting oranges grid problem with a bunch of new mechanics layered on top. Felt like they wanted to see if you could handle simulation complexity without losing your head.

Questions Asked (1)

Q1

Given a grid where cells can be infected, healthy, or immune, simulate a multi-rule infection spread over time. Two additional parameters control when a plant becomes 'severely infected' (based on how many infected neighbors it has) and how many days after that it dies. Return the number of days until nothing changes and the total number of dead plants.

Algorithms & Data StructuresSystem Design
Author's notes

This is LC 994 but they kept adding rules until it barely resembled the original.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the grid as a state machine with three states (healthy, infected, immune) and simulate day-by-day using a queue or BFS to track newly infected cells. Track for each infected cell the number of days it has been infected and the count of infected neighbors to determine when it becomes severely infected and when it dies. Continue until no state changes occur, counting the total days and dead plants.

Pro tip: Clarify the exact rules upfront: whether immunity is permanent, if infected cells can recover, and how the neighbor count is computed (e.g., 4-directional vs 8-directional). Also, consider edge cases like initial infected cells and whether they can become severely infected immediately.

1. Clarify rules and parameters

Ask clarifying questions to confirm the state transitions, neighbor definition, and the two parameters (threshold for severe infection and days until death). Ensure you understand the initial grid setup and what constitutes 'nothing changes'.

2. Choose data structures

Use a 2D array to represent the grid states. Maintain auxiliary structures: a queue for BFS to process newly infected cells, and dictionaries or arrays to track infection duration and neighbor counts for each infected cell.

3. Simulate day by day

At each day, process all infected cells: update their neighbor counts, check if they become severely infected (based on threshold), and if severely infected for the required days, mark them as dead. Then spread infection to healthy neighbors of infected cells (if not immune).

4. Detect termination and count

After each day, check if any state changed. If no changes, stop and return the number of days elapsed and the total dead plants. Otherwise, increment the day counter and continue.

5. Optimize and analyze complexity

Discuss time and space complexity: O(days * cells) in naive simulation, but can be optimized using BFS with a queue to process only affected cells. Mention potential optimizations for large grids.

Key Points to Mention

  • State representation: healthy, infected, immune, severely infected, dead (or track severe as a flag).
  • Neighbor counting: use 4-directional or 8-directional based on problem statement; clarify.
  • Infection spread: only healthy cells adjacent to infected cells become infected; immune cells are unaffected.
  • Severe infection threshold: a parameter that triggers when an infected cell has >= N infected neighbors.
  • Death timer: after being severely infected for D days, the cell dies.
  • Termination condition: simulation stops when no cell changes state in a day; return days and dead count.

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