Sort by

recency

|

3011 Discussions

|

  • + 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;
     }
    
  • + 0 comments

    How can i inegrate this code on living room wall art prints ? can any one guide me I am using kadence theme in wordpress.

  • + 0 comments

    Sliding window technique O(n)

    JAVA

        public static int birthday(List<Integer> s, int d, int m) {
            int n = s.size();
            int count = 0;
            int sum = 0;
            
            for (int i = 0; i < m; i++) {
                sum += s.get(i);
            }
            
            if (sum == d)
            count++;
            
            for (int i = m; i < n; i++) {
                sum += s.get(i);
                sum -= s.get(i - m);
                if (sum == d)
                count++;
            }
            
            return count;
        }
    
  • + 0 comments

    JS

    function birthday(s, d, m) {
        return s.slice(0,(s.length-m+1)).reduce((acc, el, idx)=>{
            if(s.slice(idx,idx+m).reduce((acc,val)=>val+acc)==d) return acc+1
            return acc
        },0)
    }
    
  • + 0 comments

    JavaScript

    function birthday(s, d, m) {
        
        let ways=0;
        
        for(let i=0;i<s.length;i++){
            
            if(s.length>1){
            let cut_slice=s.slice(i,m);
            m+=1;
                    
            let sum_of_cut_slice=0;
            
            for(let j=0;j<cut_slice.length;j++){
                sum_of_cut_slice+=cut_slice[j];
                }
                
            if(sum_of_cut_slice==d){
                ways+=1;
                }
                
            }
            
            else{
                if(s[0]==d){
                ways+=1;    
                }
            }
        }
        
        return ways;
    
    }