Active heart rate blocks

Write codeEasy12 min

Your task

A heart-rate monitor samples once per minute. A stretch of k consecutive minutes counts as an "active block" if its average rate is at least threshold. Given rates, the block length k (1 <= k <= number of samples), and threshold, return how many of the n - k + 1 blocks are active. Compare sums to k * threshold so everything stays in integers. Example: rates = [100, 120, 140, 90, 110], k = 2, threshold = 110 gives 3.

Examples

count_active_blocks(rates: list[int], k: int, threshold: int) -> int
Example 1
Inputcount_active_blocks([100, 120, 140, 90, 110], 2, 110)
Output3