← 返回 salesforce 的题目列表Maximum Requests in a Time Window
类型:online_judge
Problem: Maximum Requests in a Time Window
You are given an integer array timestamp, where timestamp[i] is the time when a request was received, and an integer windowSize.
A time window is an inclusive interval:
[start, start + windowSize - 1]
You may choose any valid start. Return the maximum number of requests whose timestamps fall within some window of size windowSize.
Input
timestamp: an array of integers (not necessarily sorted; duplicates allowed)
windowSize: a positive integer
Output
An integer: the maximum number of timestamps in any such window
Constraints
1 <= n <= 2 * 10^5
1 <= timestamp[i] <= 10^9
1 <= windowSize <= 10^9
Example 1
Input:
[1, 3, 7, 5]
windowSize = 4
Output:
2
Example 2
Input:
[2, 2, 3]
windowSize = 1
Output:
2
Example
Input
4
1 3 7 5
4
Output
2