Given an array of integers arr and two integers k and threshold, return the number of sub-arrays of size k and average greater than or equal to threshold.

&nbsp;
Example 1:

Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively. All other sub-arrays of size 3 have averages less than 4 (the threshold).


Example 2:

Input: arr = [11,13,17,23,29,31,7,5,2,3], k = 3, threshold = 5
Output: 6
Explanation: The first 6 sub-arrays of size 3 have averages greater than 5. Note that averages are not integers.


&nbsp;
Constraints:


	1 &lt;= arr.length &lt;= 105
	1 &lt;= arr[i] &lt;= 104
	1 &lt;= k &lt;= arr.length
	0 &lt;= threshold &lt;= 104


class Solution:
    def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
        wstart = wsum = count = 0
        
        for wend in range(len(arr)):
            wsum += arr[wend]
            
            if wend >= k:
                wsum -= arr[wstart]
                wstart += 1
            if (wsum//k) >= threshold and (wend-wstart+1) == k: 
                count += 1
        return count
class Solution {
    public int numOfSubarrays(int[] arr, int k, int threshold) {
        int average=0,count=0,start=0,sum=0;       
        for(int i=0;i<arr.length;i++){
            sum+=arr[i];
            if(i>=k-1){
                average=sum/k;
                if(average>=threshold) count++;
                sum-=arr[start];          
                start++;   
            }          
        }
        return count;  
    }
}
class Solution {
public:
    int numOfSubarrays(vector<int>& arr, int k, int threshold) {
        int i=0;int j=0;int sum=0;int ans=0;
        while(j<arr.size()){
            sum+=arr[j];
            if(j-i+1<k) j++;
            else if(j-i+1==k){
               if(sum/k>=threshold){
                   ans++;
               } 
                sum-=arr[i];
                j++;
                i++;
            }  
        }
        return ans;
    }
};
var numOfSubarrays = function(arr, k, threshold) {
    let total = 0;
    let left = 0;
    let right = k;
    // get initial sum of numbers in first sub array range, by summing left -> right
    let sum = arr.slice(left, right).reduce((a, b) => a + b, 0);
    while (right <= arr.length) {
        // move through the array as a sliding window
        if (left > 0) {
            // on each iteration of the loop, subtract the val that has fallen out of the window, 
            // and add the new value that has entered the window
            sum -= arr[left - 1];
            sum += arr[right - 1];
        }
        if (sum / k >= threshold) {
            total++;
        }
        left++;
        right++;
    }
    return total;
};
Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold