← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
You are given an m x n grid that represents a flower bed. Each cell can be in one of three states: 0 (healthy flower), 1 (infected flower), or 2 (immune / dead flower). Every day the disease spreads: any healthy flower that is 4-directionally adjacent to at least one infected flower becomes infected itself. Immune flowers never change state. After the daily spread, you may optionally immunize (convert to state 2) any single still-healthy flower; immunization happens instantly before the next day’s spread begins. Return the minimum number of days that must elapse until every flower is either infected or immune. If it is impossible to infect every flower, return -1.