Minimum Hours Until Every Server Rack Receives a Security Patch
Last updated: November 29, 2026
Quick Overview
A data center floor is a grid where 1 is an unpatched server, 2 is a patched server and 0 is empty space. Every hour, each patched server patches its unpatched neighbors up, down, left and right. Return the hours until all servers are patched, or -1 if some can never be reached.
Amazon
November 29, 20260
0
0 solved
A data center floor is a grid where 1 is an unpatched server, 2 is a patched server and 0 is empty space. Every hour, each patched server patches its unpatched neighbors up, down, left and right. Return the hours until all servers are patched, or -1 if some can never be reached.
An AWS-flavored take on a well known Amazon assessment pattern. The grader checks that you see this as multi-source BFS starting from every patched server at once, not a BFS per source, and that you count levels correctly.
What the Interviewer Expects
- Recognize multi-source BFS and seed the queue with all 2s
- Process level by level to count hours
- Track remaining unpatched count to detect unreachable servers
- Avoid counting an extra hour after the last level
- Handle grids with no unpatched servers
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if patching across certain cells takes two hours instead of one?
- How would you return the patch time per server?
- How would you handle a grid too large for one machine's memory?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Grid is a list of lists of 0/1/2, possibly with zero rows. Return the minimum whole hours, 0 if nothing needs patching, or -1 if any 1 is unreachable. We may modify a copy of the grid....
High-Level Design
Seed a deque with every cell holding 2 and count the 1s. Run BFS in rounds: each round pops exactly the current queue length, and patches fresh neighbors (set to 2, decrement remaining, push). Increme...