You are given a list timestamp, where each value represents the minute at which one request occurred. You are also given an integer windowSize. Return the maximum number of requests that can be found inside any continuous time window of length windowSize minutes.
The timestamps may be given in any order. The method should count requests based on their time values, not their original positions.
Method Signature
int maximumRequestsInWindow(List<Integer> timestamp, int windowSize)
timestamp contains the request times in minutes.
windowSize is the length of each continuous time window in minutes.
- The method returns the maximum number of requests found in any valid window.
- If multiple requests have the same timestamp, each request is counted separately.
Window Rule
For a window starting at minute start, a request at minute t is inside the window if:
start ≤ t < start + windowSize
This makes the output deterministic. For example, if windowSize = 5, then a window starting at 10 includes timestamps from 10 to 14, but not 15.
Constraints
1 ≤ timestamp.size() ≤ 100,000
0 ≤ timestamp[i] ≤ 1,000,000,000
1 ≤ windowSize ≤ 1,000,000,000
Examples
Example 1
maximumRequestsInWindow(timestamp = List.of(1, 2, 3, 10, 11), windowSize = 3)
Output: 3
Explanation: The window [1, 4) contains requests at minutes 1, 2, and 3.
Example 2
maximumRequestsInWindow(timestamp = List.of(8, 1, 6, 2, 3), windowSize = 4)
Output: 3
Explanation: After considering the timestamps by time, the window [1, 5) contains requests at minutes 1, 2, and 3.
Example 3
maximumRequestsInWindow(timestamp = List.of(5, 5, 5, 6, 7), windowSize = 1)
Output: 3
Explanation: A window of size 1 can include only one exact minute. The best window is [5, 6), which contains three requests.
Example 4
maximumRequestsInWindow(timestamp = List.of(10, 15, 20, 25), windowSize = 5)
Output: 1
Explanation: Because the window is half-open, [10, 15) includes 10 but not 15. No window contains more than one request.