Loading
Loading
A sensor records a signal strength reading every second. Analysts want the strongest sustained burst: the highest total across any run of exactly k consecutive readings.
Return that maximum total. You may assume k is no larger than the number of readings.
readings = [2, 1, 5, 1, 3, 2], k = 3[2,1,5] 1 3 2sum = 82 [1,5,1] 3 2sum = 72 1 [5,1,3] 2sum = 9 — best2 1 5 [1,3,2]sum = 69Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
The window [5, 1, 3] totals 9.
Example 2
Every window is negative; the least negative pair is [-1, -2].