Multi-source BFS, seeded with all initially compromised servers at once.
Model the problem as a multi-source BFS on the grid, where all initially compromised servers are enqueued at time 0. Process level by level, incrementing time after each level, and track the maximum time reached and whether any secure servers remain unreachable. If unreachable secure servers exist, return -1; otherwise return the maximum time.
Pro tip: Clarify that this is essentially 'rotting oranges' on a grid and that multi-source BFS is optimal because each cell is processed once; also mention that you can mutate the grid in-place to save space, but discuss the trade-off of modifying input.
Confirm grid dimensions, cell values, adjacency rules, and what to return if there are no secure servers or no compromised servers. Discuss edge cases like empty grid, all secure, all compromised, or isolated secure servers.
Explain that because compromise spreads simultaneously from all compromised servers, a multi-source BFS is the natural fit. Initialize a queue with all compromised cells and count total secure servers.
While the queue is not empty, process all nodes at the current level, mark adjacent secure servers as compromised, enqueue them, and decrement the secure count. After each level, increment the minute counter.
Keep track of the maximum minutes elapsed (or the BFS depth). After BFS, if the secure count is not zero, return -1; otherwise return the maximum minutes.
State time complexity O(m*n) because each cell is visited once, and space complexity O(m*n) for the queue in the worst case. Mention that in-place modification can reduce space but alters input.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.