Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold LeetCode solution in Java
1class Solution {2public int numOfSubarrays(int[] arr, int k, int threshold) {3int average = 0, count = 0, start = 0, sum = 0;4for (int i = 0; i < arr.length; i++) {5sum += arr[i];6if (i >= k - 1) {7average = sum / k;8if (average >= threshold) count++;9sum -= arr[start];10start++;11}12}13return count;14}15}