Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold LeetCode solution in Python

1
class Solution:
2
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
3
wstart = wsum = count = 0
4

5
for wend in range(len(arr)):
6
wsum += arr[wend]
7

8
if wend >= k:
9
wsum -= arr[wstart]
10
wstart += 1
11
if (wsum // k) >= threshold and (wend - wstart + 1) == k:
12
count += 1
13
return count

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0