We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

staticintsolve(intn,int[]s,intd,intm){intsum=0;intr=0;for(inti=0;i<s.length;i++){sum+=s[i];// M is never less than 1if(i>m-1)sum-=s[i-m];if(i>=m-1&&sum==d)r++;}returnr;}

## Birthday Chocolate

You are viewing a single comment's thread. Return to all comments →

My solution in Java:

This one uses a sliding window, just like my solution. I did it slightly differently by summing the first m digits in another loop.