Spike windows: hints, no solution
Easy · Sliding window
A grid operator receives one draw reading per hour, in kilowatt-hours, from a district. A spike window is a stretch of exactly k consecutive hours whose readings add up to strictly more than a threshold.
Return how many spike windows the list contains. Overlapping windows are counted separately, so the same hour may take part in several of them. If k is larger than the number of readings, there are no windows and the answer is 0.
Examples
- Input
- draw = [2, 7, 1, 8, 2, 8], k = 3, threshold = 10
- Output
- 3
- Note
- The window totals are 10, 16, 11 and 18, so three exceed 10.
- Input
- draw = [4, 5], k = 3, threshold = 0
- Output
- 0
- Note
- There are fewer readings than k, so no window exists.
- Input
- draw = [5, 5, 5], k = 1, threshold = 5
- Output
- 0
- Note
- The single reading 5 equals the threshold, which is not above it.
Constraints
- 0 <= draw.length <= 250000
- 1 <= k <= 250000
- 0 <= draw[i] <= 500, 0 <= threshold <= 2500000
Hint 1: a nudge
How could the total of one window help you find the total of the next window without adding k numbers again?
Unlock the full hints and timed practice with a pass
The second and third hints and the timed, runner-checked practice are part of a pass.