Problem · Array
Maximum Requests in a Time Window
Learn this problemProblem statement
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.
Function
maximumRequests(window: int, timestamps: int[]) → intExamples
Example 1
window = 5timestamps = [1, 2, 3, 8, 10]return = 3The 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.