Days Until Poisoned Plants Stabilize
Reported by candidates from Apple's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The data structure that decides this Apple OA question, reported in October 2026, is a queue. Days Until Poisoned Plants Stabilize looks like a grid simulation, but rerunning a full scan every day will choke on a 500 by 500 board. If you've got an invite and 48 hours, learn the queue-driven BFS version. StealthCoder is the safety net if your mind goes blank during the live OA, but this one is very learnable beforehand.
The problem
A rectangular binary grid represents plants: 1 is poisoned and 0 is healthy. At the end of each day, every healthy plant with at least k poisoned neighbors becomes poisoned. The eight horizontally, vertically, and diagonally adjacent cells are neighbors. All changes for a day are simultaneous. Return the number of days until a full day would produce no additional poisoned plants. Function daysUntilPlantsStabilize(grid: int[][], k: int) → int Examples Example 1 grid = [[1,0,0],[0,0,0],[0,0,0]] k = 1 return = 2 The cells adjacent to the initial poison change on day 1, and the final distant cell changes on day 2. Example 2 grid = [[1,0],[0,0]] k = 2 return = 0 No healthy plant initially has two poisoned neighbors, so the grid is already stable. Constraints 1 <= grid.length, grid[i].length <= 500. Every cell is 0 or 1, and every row has the same length. 1 <= k <= 8.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is multi-source BFS with neighbor counts. Keep a count array where each cell tracks how many of its 8 neighbors are poisoned. Push every initial poisoned cell into a queue. Process the queue one day at a time: for each cell in the current level, increment the count of its healthy neighbors. If a neighbor's count reaches k, mark it poisoned for the next level and add it to the next queue. Because all changes are simultaneous, you must not poison a cell mid-day. Collect new cells first, then mark them. The common pitfall is brute force, rescanning all 250,000 cells each day, which can take many days. Another pitfall is counting the final empty day. Return the number of levels that actually produced new poisoned cells. Each cell gets enqueued once, so the total work is O(m*n*8). StealthCoder is the hedge if the level-by-level bookkeeping slips under pressure on the live OA.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Days Until Poisoned Plants Stabilize 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 would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Apple's OA.
Apple reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Days Until Poisoned Plants Stabilize FAQ
What's the trick to Days Until Poisoned Plants Stabilize?+
Multi-source BFS with a per-cell poisoned-neighbor counter. Start from all poisoned cells, spread their influence to 8 neighbors, and enqueue a cell the moment its count hits k. Each cell enters the queue once, so it's linear in grid size times eight.
Why does brute-force simulation fail here?+
Rescanning the whole grid every day costs O(m*n) per day, and the number of days can approach the grid's size on a 500 by 500 board. That's far too slow. BFS only touches cells whose neighbor counts actually changed.
How do I handle simultaneous daily updates?+
Process the queue one level at a time. While handling day d, increment neighbor counts and collect the cells that cross k into a next-day list. Only mark them poisoned after the whole level finishes, so they don't affect same-day counts.
What should the answer be when nothing ever changes?+
Zero. Example 2 shows it: with k=2, no healthy cell has two poisoned neighbors, so the grid is stable immediately. Count only the days that added new poisoned plants, not the final empty check.
How do I prepare for this in 48 hours?+
Write multi-source BFS on a grid twice from scratch, once with 4 directions and once with 8. Then add a neighbor counter and a threshold k. Test the two examples and a single-cell grid. That covers this pattern.