Sort by

recency

|

3039 Discussions

|

  • + 0 comments

    The "Subarray Division" problem typically involves finding the number of contiguous subarrays of a given array that sum up to a specific value. A common variation of this problem is where you are given an array of integers, a target sum, and a required subarray length. One effective approach to solving this problem is using CBT training in Milton Keynes the sliding window technique if the subarray length is fixed.

  • + 0 comments

    sliding window

  • + 0 comments

    The "Subarray Division" problem typically involves finding the number of contiguous subarrays of a given array that sum up to a specific value. A common variation of this problem is where you are given an array of integers, a target sum, and a required subarray length. One effective approach to solving this problem is using Snptube the sliding window technique if the subarray length is fixed.

  • + 0 comments

    python 3

    def birthday(s, d, m): chococalate = 0 total = sum(s[:m])

    if total == d:
        chococalate += 1
    
    for i in range(len(s)-m):
        total = total - s[i] + s[i+m]
    
        if total == d:
            chococalate +=1
    
    return chococalate
    
  • + 0 comments

    Here is my O(N) c++ solution, you can watch the explanation here : https://youtu.be/L2fkDuGrxiI

    int birthday(vector<int> s, int d, int m) {
        if(s.size() < m) return 0;
        int su = accumulate(s.begin(), s.begin() + m, 0), result = 0;
        if(su == d) result++;
        for(int i = m; i < s.size(); i++){
            su += s[i];
            su -= s[i-m];
            if(su == d) result++;
        }
        return result;
     }