Days Until Poisoned Plants Stabilize
Updated
Problem statement
Given a rectangular binary grid of plants and an integer k, return the number of days until a full day would produce no additional poisoned plants.
In the grid, 1 is poisoned and 0 is healthy. At the end of each day, every healthy plant with at least k poisoned neighbors becomes poisoned. All changes for a day happen at the same time. A plant's neighbors are the up to eight cells touching it horizontally, vertically, or diagonally.
Function
daysUntilPlantsStabilize(grid: int[][], k: int) → intExamples
Example 1
grid = [[1,0,0],[0,0,0],[0,0,0]]k = 1return = 2On day 1 the cells touching the poisoned corner become poisoned. Every remaining cell then touches one of them, so all of them change on day 2, which is the answer.
Example 2
grid = [[1,0],[0,0]]k = 2return = 0No healthy plant has at least k poisoned neighbors, so the grid never changes and no days are counted.
Constraints
1 <= grid.length, grid[i].length <= 500.- Every cell is
0or1, and every row has the same length. 1 <= k <= 8.
More Apple Phone Screen questions
- Subarray Product Less Than KPHONE SCREEN · Seen Nov 2026
- Evaluate DivisionPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
- Design a Food Rating SystemPHONE SCREEN · Seen Oct 2026
- Capture Surrounded Regions with Union-FindPHONE SCREEN · Seen Oct 2026
- Maintain a Consistent-Hashing RingPHONE SCREEN · Seen Oct 2026
- Count Nodes in a ChainPHONE SCREEN · Seen Oct 2026
- Run-Length DecodingPHONE SCREEN · Seen Oct 2026
- Implement Hit CounterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Grid Infection with Recovery After D DaysOpenAI · PHONE SCREENOpenAI 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
- 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
- Minesweeper Board UpdateAirbyte · ONSITE INTERVIEW
- Competitive ForagingAkuna Capital · OAAkuna Capital interview questions
Apple interview experiences
- Apple SWE Phone Screen: Subarray Products: 1 Experience
- Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
- Apple AI Coding and Related Interviews: 17 Experiences
- Apple India SWE New Grad Interviews: 5 Experiences
- Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
- Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)