-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprblm1343.java
More file actions
24 lines (24 loc) · 756 Bytes
/
prblm1343.java
File metadata and controls
24 lines (24 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class prblm1343 {
public static void main(String[] args) {
int[] arr = {2,2,2,2,5,5,5,8};
int k = 3;
int threshold = 4;
System.out.println(numOfSubarrays(arr, k, threshold));
}
public static int numOfSubarrays(int[] arr, int k, int threshold) {
int windowStart = 0;
int windowSum = 0;
int count = 0;
for (int windowEnd = 0; windowEnd < arr.length; windowEnd++) {
windowSum += arr[windowEnd];
if (windowEnd >= (k-1)) {
if (windowSum/k >= threshold) {
count++;
}
windowSum -= arr[windowStart];
windowStart += 1;
}
}
return count;
}
}