My first instinct was BFS and I got that part right.
Model the grid as a graph and use multi-source BFS starting from all initially infected cells simultaneously. Track the time each healthy cell gets infected, and after BFS, check if any healthy cell remains uninfected; if so, return -1, else return the maximum time.
Pro tip: Clarify that immune cells act as obstacles and that infection spreads in four directions; also mention that if there are no healthy cells initially, the answer is 0. This shows attention to edge cases and problem constraints.
Confirm that infection spreads to adjacent healthy cells (up, down, left, right) each minute, immune cells block spread, and if any healthy cell is unreachable, return -1. Handle cases with no healthy cells (return 0) and no infected cells (return -1 if healthy cells exist).
Add all initially infected cells to a queue and count the total number of healthy cells. Use a variable to track the number of infected healthy cells or the minutes elapsed.
Process the queue level by level (each level represents one minute). For each infected cell, check its four neighbors; if a neighbor is healthy, infect it, add to queue, and decrement the healthy count. Increment time after each level.
After BFS, if the healthy count is zero, return the elapsed time; otherwise, return -1 because some healthy cells were unreachable.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.