Sort by

recency

|

3025 Discussions

|

  • + 0 comments
    def birthday(s, d, m):
        if len(s) < m:
            return 0
        
        ways = 0
        
        for i in range(len(s) - m + 1):
            if sum(s[i:i + m]) == d:
                ways += 1
        
        return ways
    
  • + 1 comment

    def birthday(s, d, m):

    # Write your code here
    sum=0
    count=0
    for i in range(0,m):
        sum+=s[i]
    if(sum==d):
        count+=1
    for i in range(m,len(s)):
        sum+=s[i]
        sum-=s[i-m]
        if(sum==d):
            count+=1
    return count        
    
  • + 0 comments
    int birthday(vector<int> s, int d, int m) {
        int n = s.size();
        int count = 0;
        int window_sum = 0;
    
        // Calculate the initial window sum
        for (int i = 0; i < m; i++) {
            window_sum += s[i];
        }
    
        // Slide the window
        for (int i = 0; i <= n - m; i++) {
            if (window_sum == d) {
                count++;
            }
            if (i + m < n) {
                window_sum -= s[i]; // Remove the leftmost element
                window_sum += s[i + m]; // Add the rightmost element
            }
        }
    
        return count;
    }
    
  • + 0 comments
    IntStream.range(0, (s.size() - m +1))
            .forEach(
                pos-> {
                    int sum = 
                    IntStream.range(pos, (pos+m))
                        .map(e->s.get(e))
                        .sum();
                    if(sum == d) {
                        possibleCombin.set(0, possibleCombin.get(0)+1);
                    } 
                }
            );
    
  • + 0 comments

    Subarray Division sounds like a tricky yet interesting problem to tackle! It's amazing how logical thinking can help solve these challenges. Speaking of problem-solving, have you looked into Zoho CRM Implementation? It's a game-changer for managing customer relationships efficiently—perfect for streamlining workflows just like solving complex coding problems!