Posted on

Description

Submission

class Solution {
public:
    int numOfSubarrays(vector<int>& arr, int k, int threshold) {
        int i = 0, j = k;
        int sum = accumulate(arr.begin(), arr.begin() + k, 0);
        int n = arr.size();
        
        int target = threshold * k;
        
        int ret = 0;
        for(; j < n; ++i, ++j) {
            if(sum >= target) {
                ret++;
            }
 
            sum -= arr[i];
            sum += arr[j];
        }
        if(sum >= target) {
            ret++;
        }
        
        return ret;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *