Given an array of timestamps and a window size, find the maximum number of requests made within any time window defined as the closed interval [x, x + window - 1] for some integer x.
The function maximumRequests will take two inputs:
int window: the size of the time windowint timestamps[n]: array of request timestamps
The function should return an integer denoting the maximum number of requests made within any given window size.
Examples
01 · Example 1
window = 5 timestamps = [1, 2, 3, 8, 10] return = 3
The window [0, 4] contains 3 requests at timestamps 1, 2, and 3, which is the maximum among all windows of size 5. Hence, the answer is 3.
Constraints
1 <= window <= 10^91 <= n <= 2 * 10^50 <= timestamps[i] <= 10^9- It is guaranteed that
timestampsare sorted in non-decreasing order.
More IBM problems
- Query Type Frequency WindowOA · Seen Jul 2026
- Minimum Number of Non-Empty Disjoint SegmentsOA · Seen Jul 2026
- Spam Text ClassificationOA · Seen Jul 2026
- Parent Process NumberOA · Seen Jun 2026
- Request Retry CountOA · Seen Jun 2026
- Count Ideal NumbersOA · Seen Jun 2026
- Count Descending SubarraysOA · Seen Apr 2026
- Count Power Products in RangeOA · Seen Apr 2026
public int maximumRequests(int window, int[] timestamps) {
// write your code here
}window5
timestamps[1, 2, 3, 8, 10]
expected3
checking account