Grid Infection with Immune Cells Until Stable
Reported by candidates from OpenAI's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
OpenAI's May 2026 OA asks you to simulate a grid infection where healthy cells become infected based on neighbor count, but immune cells block spread. You're given a grid with healthy cells '.', infected cells 'X', and immune cells 'I'. Each day, any '.' cell with at least T infected neighbors (out of 8) becomes 'X'. Immune cells never change and don't count as infected. Your job: return the number of days until no new infections occur. This is a BFS simulation problem. StealthCoder will catch the synchronous update rule if you freeze mid-interview.
The problem
Complete the function below. The function receives the full standard input as a single string and must return the exact standard output lines for the described problem. Problem Extending the previous problem, the grid may also contain immune cells 'I': 'I' can never be infected. 'I' does not infect others (it is not counted as infected). Each day (synchronously), any healthy '.' cell with at least T infected 'X' neighbors among its 8 neighbors becomes 'X'. 'I' always stays 'I'. Return the number of days until the grid becomes stable (no new infections occur). Example Input 3 3 1 I...X.... Output 1 Function Description Complete solveGridInfectionWithImmuneCells. It has one parameter, String input, containing the full stdin payload. Return the stdout payload as an array of lines, without trailing newline characters. The returned string array must match the expected standard output lines for the sample input. Use the limits and requirements stated in the prompt.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick here is synchronous updates. You can't infect cells in-place each day, or later cells won't see the original state. On each iteration, scan the entire grid, mark which '.' cells should become 'X' based on the current state, then apply all changes at once. Use BFS or layer-by-layer simulation to track infected cells and count neighbors in O(rows times cols) per day. The immune cells 'I' act as barriers they don't spread infection and don't get infected. Count days until a full pass produces zero new infections. Common pitfall: mutating the grid during iteration instead of buffering changes. If you blank on the synchronous rule, StealthCoder reads the grid on screen and feeds you the pattern instantly.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Grid Infection with Immune Cells Until Stable cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as rotting oranges. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass OpenAI's OA.
OpenAI reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Grid Infection with Immune Cells Until Stable FAQ
Do immune cells 'I' count as neighbors when checking the T threshold?+
No. Only infected 'X' cells count. A '.' surrounded by 7 'I' and 1 'X' with T=1 will become infected. Immune cells are transparent to the infection logic, they just can't be infected themselves.
What's the synchronous update rule in plain English?+
All infections happen at the same time. You check the entire grid's state on day N, decide which cells flip to 'X', then apply all flips together. Don't modify the grid mid-scan or you'll infect cells twice in one day.
How do I avoid timeout on large grids?+
Don't rescan the entire grid every day. Track only the boundary cells (those adjacent to infected cells). Use a queue of edge cells and shrink it as the infection stabilizes. Once no new infections occur in a pass, you're done.
Is this really just BFS with a twist?+
Yes. BFS spreads outward from infected cells one layer per day. The twist is the T threshold and immune barriers. Instead of infecting all adjacent cells, infect only those with T or more infected neighbors. Immune cells act as walls.
What if the grid is already stable on day 0?+
Return 0. If no '.' cell has T or more infected neighbors initially, no infections occur and the grid is already stable. Run one check at the start to confirm before entering the simulation loop.