Skip to content

Commit e4c39e0

Browse files
authored
Create 1343-number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold.kt
1 parent 8776fb9 commit e4c39e0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
fun numOfSubarrays(arr: IntArray, k: Int, threshold: Int): Int {
3+
4+
var sum = 0
5+
var res = 0
6+
7+
for (i in 0 until k-1) sum += arr[i]
8+
9+
for (i in k-1 until arr.size) {
10+
sum += arr[i]
11+
if (sum / k >= threshold) res++
12+
sum -= arr[i-k+1]
13+
}
14+
15+
return res
16+
}
17+
}

0 commit comments

Comments
 (0)