← Openai Interview Insights

Openai·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Coding round at OpenAI for a software engineer role. One problem, grid-based BFS with a twist. Felt manageable if you've seen the classic infection spread problem before.

Questions Asked (1)

Q1

Given a grid where cells are either infected ('X'), healthy ('.'), or immune ('I'), find the number of days until the infection stops spreading. Infected cells spread to all 8 neighbors each day, but immune cells can never be infected and block the spread.

Algorithms & Data Structures
Author's notes

The immune cells are the real wrinkle here.

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 where all initially infected cells are sources. Each BFS layer represents one day, and you track the maximum distance to any healthy cell that gets infected; if some healthy cells remain unreachable, the infection stops after the last layer that infected at least one cell.

Pro tip: Clarify edge cases upfront: if there are no infected cells, return 0; if all healthy cells are blocked by immune cells, return 0; and if the grid is empty, return 0. Also, mention that you'll use a queue to process cells level by level to naturally count days.

1. Clarify the problem and edge cases

Confirm the grid dimensions, the meaning of each cell type, and what should be returned if no spread occurs. Discuss edge cases like empty grid, no infected cells, or all cells immune.

2. Choose the algorithm

Explain that multi-source BFS is ideal because it simulates simultaneous spread from multiple sources and naturally tracks the number of days as BFS levels.

3. Initialize the BFS queue and day counter

Enqueue all initially infected cells with distance 0. Initialize a variable to track the maximum days and a count of remaining healthy cells.

4. Process BFS level by level

For each level, process all cells currently in the queue, infecting all 8 neighboring healthy cells, marking them infected, and enqueueing them with distance+1. Increment the day counter after each level if any new infections occurred.

5. Return the result and analyze complexity

After BFS, if all healthy cells are infected, return the maximum distance; otherwise, return the maximum distance achieved (since infection stops). State time and space complexity: O(R*C) time and O(R*C) space.

Key Points to Mention

  • Multi-source BFS to simulate simultaneous spread from all initially infected cells.
  • 8-directional neighbor traversal (including diagonals).
  • Immune cells act as obstacles and are never enqueued.
  • Track days by processing BFS level by level (e.g., using queue size or distance markers).
  • Edge cases: no infected cells, no healthy cells, all healthy cells blocked, empty grid.
  • Time and space complexity: O(R*C) for both, where R and C are grid dimensions.

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