Skip to the code
+10 XP

#124 Busiest Stretch of Requests

easy

An API dashboard stores how many requests arrived in each minute in perMinute. The on-call engineer wants the busiest stretch of exactly k minutes in a row.

Write busiestStretch(perMinute, k) that returns the largest total number of requests over any k consecutive minutes. k is never more than the number of minutes.

Example 1

Input: perMinute = [4,2,7,1,8,3], k = 3
Output: 16

Minutes 2 to 4 have 7 + 1 + 8 = 16 requests.

Example 2

Input: perMinute = [5,5,5], k = 3
Output: 15

There is only one stretch of 3 minutes.

Constraints

  • 1 <= k <= perMinute.length <= 200000
  • 0 <= perMinute[i] <= 10^4
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).