An integer gap defines the maximum allowed time difference, in seconds, to consider a retry.
Two arrays are provided:
requestIds, where each element represents the request ID of a logtimestamps, where each element represents the time of the corresponding log, sorted in non-decreasing order
A retry occurs when two consecutive logs for the same request ID have a time difference of at most gap.
Compute the total number of retries across all request IDs and return the result.
Examples
01 · Example 1
gap = 10 requestIds = ["r1", "r1", "r1", "r2", "r2"] timestamps = [100, 105, 200, 300, 302] return = 2
The table below shows the total number of retries for each request ID:
| Request ID | Timestamps | Retry Pairs | Retry Count |
|---|---|---|---|
r1 | [100, 105, 200] | (100, 105) | 1 |
r2 | [300, 302] | (300, 302) | 1 |
The total number of retries = 1 + 1 = 2.
Hence, the answer is 2.
Constraints
1 ≤ gap ≤ 10^91 ≤ n ≤ 2 * 10^60 ≤ timestamps[i] ≤ 10^9
More IBM problems
- Parent Process NumberOA · Seen Jun 2026
- Count Ideal NumbersOA · Seen Jun 2026
- Count Descending SubarraysOA · Seen Apr 2026
- Count Power Products in RangeOA · Seen Apr 2026
- Minimum Operations to Make Alternating Binary StringSeen Feb 2026
- Minimum Number of Non-Empty Disjoint SegmentsSeen Feb 2026
- Count Unstable ProcessesOA · Seen Feb 2026
- Longest Balanced Binary SubarrayOA · Seen Feb 2026
public int getRetryCount(int gap, String[] requestIds, int[] timestamps) {
// write your code here
}
gap10
requestIds["r1", "r1", "r1", "r2", "r2"]
timestamps[100, 105, 200, 300, 302]
expected2
checking account