Problem · Hash Table

Service Timeout Detection

Learn this problem
EasyIBM logoIBMFULLTIMENEW GRADOA
See IBM hiring insights

Problem statement

Heartbeat events are recorded with a timestamp and a service identifier. A service times out if the gap between any two consecutive heartbeats for that service is strictly greater than a given threshold.

Return all service identifiers that time out at least once, sorted lexicographically.

Function

detectTimedOutServices(timestamps: int[], serviceIds: String[], threshold: int) → String[]

Examples

Example 1

timestamps = [10, 20, 80, 10, 65]serviceIds = ["svc1", "svc1", "svc1", "svc2", "svc2"]threshold = 30return = ["svc1", "svc2"]

svc1 has a 60-second gap between heartbeats at 20 and 80, and svc2 has a 55-second gap between 10 and 65. Both exceed the threshold.

Constraints

  • 1 <= n <= 2 * 10^5
  • 1 <= timestamps[i] <= 10^9
  • 0 <= threshold <= 10^9

More IBM problems

drafts saved locally
public String[] detectTimedOutServices(int[] timestamps, String[] serviceIds, int threshold) {
  // write your code here
}
timestamps[10, 20, 80, 10, 65]
serviceIds["svc1", "svc1", "svc1", "svc2", "svc2"]
threshold30
expected["svc1", "svc2"]
checking account