Problem statement

https://binarysearch.com/problems/Number-of-K-Length-Sublists-with-Average-at-Least-Target/

Solution

Equal to Leetcode 1343. Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold.

Complexity

It is O(n) for time and space.

Code

class Solution:
    def solve(self, arr, k, threshold):
        acc = [0] + list(accumulate(arr))
        return sum(acc[i + k] - acc[i] >= threshold * k for i in range(len(arr) - k + 1))