Your question is Infection Simulation Stop Time. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
OpenAI simulation tooling can model how a condition spreads through a discrete region. Given an M x N grid, calculate how many days are required for infection to spread from all initially infected cells to every reachable healthy cell.
Each cell contains:
0, an empty cell that cannot be infected1, a healthy cell2, an initially infected cellAt the end of each day, every infected cell infects its healthy neighbors in the four cardinal directions. Newly infected cells begin spreading on the following day. Return the number of days until no healthy cells remain reachable. Return -1 if at least one healthy cell can never be infected.
Implement infect_days(grid), where grid is a non-empty list of non-empty lists containing only 0, 1, and 2. Return an integer. The function may modify grid in place.
def infect_days(grid):