A refrigerated warehouse logs an integer temperature reading every hour, for n hours. For a fixed window length k, consider every contiguous window of exactly k consecutive hours. A window is "compliant" if its MINIMUM temperature is between lo and hi inclusive.
Count how many windows are compliant.
Line 1: four integers n, k, lo, hi (with lo <= hi).
Line 2: n space-separated integers, the temperature readings.
A single integer: the number of compliant windows.
Example 1
Input
5 3 1 5 4 2 9 1 5
Expected
3
Explanation
Windows [4,2,9] (min 2), [2,9,1] (min 1) and [9,1,5] (min 1) all have minimums within [1,5], so all 3 windows are compliant.
Example 2
Input
4 2 10 20 1 2 3 4
Expected
0
Explanation
Every window's minimum (1, 2 or 3) is far below the required range [10,20], so no window is compliant.
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 →