Leetcode 1445 Solution
This article provides solution to leetcode question 1445 (number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold)
Access this page by simply typing in "lcs 1445" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
Solution
class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
i = k - 1
s = sum(arr[:k - 1])
ans = 0
while i < len(arr):
s += arr[i]
if s >= threshold * k:
ans += 1
s -= arr[i - (k - 1)]
i += 1
return ans