Problem · Array
Maximum Requests in Window
Learn this problemProblem statement
Given a series of request timestamps, find the maximum number of requests that occur within any continuous time window of a specified length.
The function receives:
timestamp: request timestamps in minuteswindowSize: duration of the time window in minutes
Return the maximum number of requests observed in any window of length windowSize minutes.
Function
maxRequestInWindow(timestamp: int[], windowSize: int) → intExamples
Example 1
timestamp = [1,3,7,5]windowSize = 4return = 2Windows such as [1,4], [3,6], and [5,8] each contain two requests. The maximum is 2.
Example 2
timestamp = [2,2,3]windowSize = 1return = 2The window [2,2] includes both requests at time 2.
Constraints
1 <= timestamp.length <= 2 * 10^51 <= timestamp[i] <= 10^91 <= windowSize <= 10^9