Trains the technique from
LeetCode 1343Number of Sub-arrays of Size K and Average Greater than or Equal to ThresholdThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A rooftop sensor writes one integer reading per minute into the list readings. An analyst inspects every window of exactly span consecutive readings and keeps the window when the mean of its readings is at least bar.
Two windows are different when they start at different minutes, so a list of n readings has n - span + 1 windows to inspect.
Return how many of those windows the analyst keeps.
Example 1
The five windows total 18, 15, 19, 13 and 17, so their means are 6, 5, 6.33..., 4.33... and 5.66.... Only the first and the third reach a mean of 6.
Example 2
The three windows total 9, 2 and 9, giving means 4.5, 1 and 4.5. The first and the last reach the bar of 4.
Example 3
The span equals the number of readings, so there is one window; its mean is 4, which reaches the bar.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def count_qualifying_windows(readings: list[int], span: int, bar: int) -> int:public int countQualifyingWindows(int[] readings, int span, int bar)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.