You are given an integer array requests where requests[i] is the number of requests a server received during second i. You are also given an integer k, the length of a contiguous time window in seconds.
The throughput of a window is the total number of requests handled during that window. Find the maximum throughput over any contiguous window of exactly k seconds and return it.
Function Signature
def max_throughput(requests: list[int], k: int) -> int:
Constraints
-
1 <= k <= len(requests) <= 10^5
-
0 <= requests[i] <= 10^4
Examples
Input: requests = [1,3,2,6,4,8,5], k = 3
Output: 18
The windows of length 3 sum to 6, 11, 12, 18 and 17. The largest is [6, 4, 8], which sums to 18.
Input: requests = [5,1,2,7,3,4], k = 2
Output: 10
The windows of length 2 sum to 6, 3, 9, 10 and 7, so the best window is [7, 3]. The window [2, 7] reaches only 9.
Input: requests = [2,9,1], k = 3
Output: 12
When k equals the array length there is exactly one window, the whole array, and its sum is 12.