Find the maximum request throughput in any k-second window

Quick Overview

Given the number of requests a server receives each second and a window length k, find the largest total number of requests in any k consecutive seconds. It tests fixed-size sliding window reasoning, off-by-one care in the window update, and a linear-time solution with constant extra space.

Find the maximum request throughput in any k-second window

Company: Citadel

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

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 ```python def max_throughput(requests: list[int], k: int) -> int: ``` ### Constraints - `1 <= k <= len(requests) <= 10^5` - `0 <= requests[i] <= 10^4` ### Examples ```text 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. ```text 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. ```text 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.

Overview: Given the number of requests a server receives each second and a window length k, find the largest total number of requests in any k consecutive seconds. It tests fixed-size sliding window reasoning, off-by-one care in the window update, and a linear-time solution with constant extra space.

Citadel logo
Citadel
Nov 25, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

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.