ORIGINAL CODING QUESTION
Patch rollout minutes
Desks in an office grid hold 0 for an empty desk, 1 for a laptop still waiting for a security patch and 2 for a laptop that already has it. Every minute, each patched laptop passes the patch to waiting laptops directly above, below, left or right of it, all at the same time. Return the number of minutes until no laptop is waiting, 0 if none waits at the start, or -1 if some waiting laptop can never receive the patch.
Original exercise · medium. Editorial role relevance does not imply a company has asked this question.
Input and output
rows cols, then rows×cols cell values in row-major order. Each cell is 0, 1 or 2.
Constraints
1 ≤ rows,cols ≤ 8; every cell is 0, 1 or 2.
Example 1
Input
3 3 2 1 1 1 1 0 0 1 1
Output
4
The patch reaches the bottom-right laptop after four minutes.
Example 2
Input
2 2 2 0 0 1
Output
-1
The waiting laptop touches the patched one only diagonally, so it is never patched.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
All initially patched laptops spread at once, so they all start together.
Hint 2
Run one breadth-first search seeded with every 2 cell at minute 0.
Hint 3
After the search, any 1 cell without a time means -1; otherwise report the largest time.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →