A heartbeat detector records the last time each node reported that it was alive. At time now, a node is considered failed when its heartbeat age exceeds the configured timeout.
Design a HeartbeatFailureDetector class:
HeartbeatFailureDetector() creates a stateless detector.int[] failedNodes(int[] lastSeen, int now, int timeout) returns the indices of failed nodes in ascending order.
Node i is failed when:
The comparison is strict. A heartbeat exactly timeout time units old is still valid. Treat each call independently and do not mutate lastSeen.
Example 1:
Input:
Output:
Explanation: Nodes 2 and 3 have been silent for 20 and 30 time units, both greater than 15.
Example 2:
Input:
Output:
Explanation: Node 3 has age 5, equal to the timeout, so it is not returned.
Constraints
1 <= lastSeen.length <= 10^50 <= lastSeen[i] <= now <= 10^90 <= timeout <= 10^9- Return zero-based node indices in ascending order.
- At most
100 calls are made to failedNodes.