← Openai Interview Insights

Openai·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Interviewed for a software engineer role at OpenAI and got a grid simulation problem that was sneakily harder than it looked on the surface. The BFS angle was obvious but tracking the recovery/immunity timing tripped me up for a bit.

Questions Asked (1)

Q1

Given a grid where each person starts healthy, infected, or immune: infected people spread to adjacent healthy neighbors each day, and after D days an infected person recovers and becomes permanently immune. How many days until no more state changes are possible?

Algorithms & Data Structures
Author's notes

My first instinct was plain BFS and I started coding before fully thinking through the immunity part.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the grid as a graph and simulate the infection spread day by day using BFS, tracking each infected cell's recovery day. The process ends when no healthy cells are adjacent to infected cells and all infected cells have recovered.

Pro tip: Clarify edge cases upfront: what if there are no infected cells initially? Also, mention that you can optimize by stopping simulation early if no new infections occur and all infected have recovered.

1. Clarify problem details

Ask about grid size, initial states, D value, and whether immunity is permanent. Confirm that recovery happens after exactly D days and that infected can spread each day before recovery.

2. Choose representation

Represent the grid as a 2D array and use a queue for BFS. Track infection day and recovery day for each cell, or maintain separate sets for healthy, infected, and immune.

3. Simulate day by day

For each day, process all currently infected cells: they infect adjacent healthy cells (to be infected next day) and if their infection duration reaches D, they become immune. Use a queue to manage the order.

4. Detect termination

Stop when no new infections occur and all infected cells have recovered. The answer is the number of days simulated until no state changes are possible.

5. Analyze complexity

Time complexity is O(N*M) since each cell is processed at most once. Space complexity is O(N*M) for the grid and queue.

Key Points to Mention

  • Use BFS to simulate the spread level by level (day by day).
  • Track recovery time for each infected cell to know when it becomes immune.
  • Handle edge cases: no infected initially, all immune, grid boundaries.
  • The process stops when no healthy cells are adjacent to infected cells and all infected have recovered.
  • Time complexity O(N*M) and space O(N*M).
  • Potential optimization: early termination if no new infections and no active infected.

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