A factory floor sensor reports one integer temperature reading per minute. You are given the full sequence of n readings, a window length k, and an integer alert threshold t.
Consider every contiguous window of exactly k consecutive readings (there are n - k + 1 such windows, each one starting one minute later than the previous one). A window triggers an alert when the AVERAGE of its k readings is greater than or equal to t. Compare the average exactly, without rounding: a window with sum S triggers an alert exactly when S >= t * k.
Count how many of the n - k + 1 windows trigger an alert.
Line 1: three integers n, k, t separated by spaces.
Line 2: n space-separated integers, the readings in chronological order.
A single integer: the number of windows whose average is >= t.
Example 1
Input
4 2 4 3 5 1 6
Expected
1
Explanation
The windows are [3,5] (sum 8, meets 4*2=8), [5,1] (sum 6, below 8) and [1,6] (sum 7, below 8). Only one window qualifies.
Example 2
Input
6 3 0 -2 -2 -2 5 5 5
Expected
3
Explanation
The window [-2,-2,-2] has a negative average and is skipped, while [-2,-2,5], [-2,5,5] and [5,5,5] all have averages >= 0, giving 3.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →