Imagine a network of servers represented as an undirected graph. Server 0 is the master server, and all other servers are data servers. Each data server 'i' sends a message to server 0 at time 0 and continues to resend the message every patience[i] seconds until it receives an acknowledgment from server 0. A message takes a certain amount of time to travel across each edge. Once server 0 receives a message, it immediately sends an acknowledgment back. Your goal is to find the first second when the entire network becomes idle (no messages are traveling on any edges).
This the Time When the Network Becomes Idle interview question is used by companies like Atlassian to test a candidate's ability to model a complex communication system using graph algorithms. It requires finding the shortest path from each node to the master server (BFS) and then using that distance to calculate the total time the server remains active. It evaluates your ability to combine graph traversal with mathematical modeling of resending logic.
This problem follows the Array, Breadth-First Search, Graph interview pattern.
d[i] from server 0 to every other server i.round_trip = 2 * d[i].patience[i] seconds as long as it hasn't received the ACK.last_send = ((round_trip - 1) // patience[i]) * patience[i].last_send + round_trip.max(last_send + round_trip) + 1 across all data servers.Server 1 is 2 units away from Server 0. Round trip = 4. Patience = 3.
In "The Time When the Network Becomes Idle coding problem," a common mistake is incorrectly calculating the time of the last resend. Many candidates forget the round_trip - 1 logic, which accounts for the fact that a message arriving at the same time as a resend would prevent that resend. Another error is not using BFS to find the shortest paths, as the graph edges are unweighted.
When dealing with network latency or message resending, always draw a timeline to visualize the events. Understanding the relationship between round-trip time and resending intervals is key to solving these types of problems. For graph traversal, remember that BFS is optimal for finding shortest paths in unweighted graphs.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Shortest Distance After Road Addition Queries I | Medium | Solve | |
| Maximum Candies You Can Get from Boxes | Hard | Solve | |
| Minimum Operations to Convert Number | Medium | Solve | |
| Shortest Path with Alternating Colors | Medium | Solve | |
| Shortest Cycle in a Graph | Hard | Solve |