FastPrepGrid Infection with Recovery After D Days
Problems/Grid Infection with Recovery After D Days

Grid Infection with Recovery After D Days

OpenAI logoOpenAI● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: 🐼 Corrected on 2026-07-18. This problem matches about 95% of the reported source. It came from a 60-minute General Coding technical phone screen, not an online assessment. The source confirms 8-neighbor threshold infection, recovery after D days, and infection before recovery on the same day.

You are given a grid of characters, grid. Each cell is one of three kinds:

  • '.': healthy. It can be infected.
  • 'X': infected.
  • 'I': immune. It can never be infected, it never changes, and it does not count as infected when we look at the neighbors of another cell.

You are also given two integers, threshold and recoveryDays.

Every infected cell has an age, in days. A cell that is infected at the start has age 1. The grid changes one day at a time. All cells update at the same time, and every change on a day depends only on the grid as it was at the start of that day. On each day:

  • A healthy cell becomes infected at the end of the day if at least threshold of its 8 neighbors (up, down, left, right and the 4 diagonals) are infected. A newly infected cell has age 1 after that day.
  • An infected cell whose age is exactly recoveryDays becomes immune at the end of the day. Any other infected cell gets 1 day older.

An infected cell still counts as infected for the whole day on which it recovers. So a cell infected at the end of day k has age 1 after day k, and it becomes immune at the end of day k + recoveryDays.

Return the number of days until no infected cell is left. If there is no infected cell at the start, return 0.

Function

daysUntilNoInfection(grid: char[][], threshold: int, recoveryDays: int) → int

Examples

Example 1

grid = [[".","X","."],[".",".","."],[".",".","."]]threshold = 1recoveryDays = 1return = 3
grid
0120.X.1...2...

Only the top middle cell is infected. With recoveryDays 1, every infected cell stays infected for exactly one day.

Day 1: every cell next to the infected cell has 1 infected neighbor, so those 5 cells (the rest of the top row and the whole middle row) become infected. The first infected cell has age 1, which equals recoveryDays, so it becomes immune.

Day 2: the 5 infected cells make the 3 bottom cells infected, and then they become immune.

Day 3: the 3 bottom cells become immune. No infected cell is left, so the answer is 3.

Constraints

  • 1 <= grid.length <= 100
  • 1 <= grid[i].length <= 100
  • Every row of grid has the same length
  • Each grid[i][j] is '.', 'X' or 'I'
  • 1 <= threshold <= 8
  • 1 <= recoveryDays <= 100
  • The answer is always finite: every infected cell becomes immune after recoveryDays days, and an immune cell is never infected again

More OpenAI Phone Screen questions

  • Secret Number Search with One-Call-Delayed FeedbackPHONE SCREEN · Seen Nov 2026
  • Determine the Winner of Three-Card HandsPHONE SCREEN · Seen Nov 2026
  • Sparse Plant Infection SimulationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Light Source Hits: Sample, Compare, and FitPHONE SCREEN · Seen Nov 2026
  • Rectangle Point Coverage CountsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Adaptive Calibration ErrorPHONE SCREEN · Seen Nov 2026
  • Elevator Scheduling SimulationPHONE SCREEN · Seen Nov 2026
  • Evaluate Noisy AnnotatorsPHONE SCREEN · Seen Oct 2026
  • Network Endpoint or Cycle BoundaryOA · PHONE SCREEN · Seen Oct 2026
  • Message Event AggregationPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Days Until Poisoned Plants StabilizeApple · PHONE SCREENApple interview questions
  • Process Minesweeper Game OperationsAmperity · PHONE SCREENAmperity interview questions
  • Xiangqi Horse ReachabilityeBay · PHONE SCREENeBay interview questions
  • Drop and Eliminate Adjacent PiecesSnowflake · PHONE SCREENSnowflake interview questions
  • Simulate Orchard Rot SpreadAirbnb · OAAirbnb interview questions
  • Simulate Orchard Rot SpreadCapital One · OACapital One interview questions
  • Explore an Unknown Grid and Find a PathLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Minesweeper Board UpdateUber · ONSITE INTERVIEWUber interview questions
  • Minesweeper Board UpdateClay · ONSITE INTERVIEW
  • Simulate Orchard Rot SpreadZipRecruiter · OAZipRecruiter interview questions

OpenAI interview experiences

  • OpenAI OA: What It Tests (2026)
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public int daysUntilNoInfection(char[][] grid, int threshold, int recoveryDays) {
        // write your code here
    }

}
Checking account…