← Openai Interview Insights

Openai·Machine Learning Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
Jun 2026Remote

Summary

One coding round at OpenAI for an ML Engineer role, two problems but the main event was a grid-based infection spread problem that's basically a BFS exercise if you've seen LeetCode 994 before.

Questions Asked (1)

Q1

Given an m x n grid where each cell is empty, a healthy person, or an infected person, infection spreads to 4-directional healthy neighbors every minute. Return the minimum number of minutes until no healthy person remains, or -1 if it's impossible.

Algorithms & Data Structures
Author's notes

Multi-source BFS, which I knew going in, but I fumbled the -1 case for a solid two minutes.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the grid as a graph and use multi-source BFS starting from all initially infected cells simultaneously. Track the time each healthy cell becomes infected, and after BFS, check if any healthy cells remain uninfected; if so, return -1, otherwise return the maximum time.

Pro tip: Clarify edge cases upfront (e.g., no healthy cells, no infected cells, unreachable healthy cells) and mention that BFS is optimal because infection spreads uniformly in time, similar to shortest path in an unweighted graph.

1. Understand the problem and edge cases

Restate the problem: infection spreads to 4-directional healthy neighbors each minute. Identify edge cases: no healthy cells (return 0), no infected cells but healthy cells exist (return -1), and healthy cells unreachable from any infected cell (return -1).

2. Choose the right algorithm

Recognize this as a multi-source shortest path problem on an unweighted grid. BFS is ideal because it explores level by level, naturally tracking the minute each cell gets infected.

3. Implement multi-source BFS

Initialize a queue with all infected cells and set their time to 0. While the queue is not empty, pop a cell and for each healthy neighbor, mark it infected, set its time to current time + 1, and enqueue it. Keep track of the maximum time.

4. Check for remaining healthy cells

After BFS, scan the grid to see if any healthy cells remain. If yes, return -1; otherwise, return the maximum time recorded.

5. Analyze complexity and optimize

Time complexity is O(m*n) since each cell is processed once. Space complexity is O(m*n) for the queue and time tracking. Mention that in-place modification of the grid can save space if allowed.

Key Points to Mention

  • Multi-source BFS to simulate simultaneous infection spread
  • Time tracking: each level of BFS corresponds to one minute
  • Edge cases: no healthy cells, no infected cells, unreachable healthy cells
  • Complexity: O(m*n) time and space, optimal for grid traversal
  • Use of queue and possibly in-place modification to save space
  • Comparison with DFS: BFS guarantees minimum time due to level-order traversal

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