Skip to content

Commit 96bd963

Browse files
Merge pull request #3039 from benmak11/1343
Create 1343-number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold.java
2 parents b792950 + 14f7098 commit 96bd963

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public int numOfSubarrays(int[] arr, int k, int threshold) {
3+
int res = 0, currSum = 0;
4+
5+
for (int i = 0; i < k - 1; i++) {
6+
currSum += arr[i];
7+
}
8+
9+
for (int l = 0; l < arr.length - k + 1; l++) {
10+
currSum += arr[l + k - 1];
11+
if ((currSum / k) >= threshold) {
12+
res++;
13+
}
14+
currSum -= arr[l];
15+
}
16+
return res;
17+
}
18+
}

0 commit comments

Comments
 (0)