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.
publicstaticintbirthday(List<Integer>s,intd,intm){intcount=0;// current sum of the windowintsteps=0;// current window sizeinttotal=0;// total valid segmentsfor(inti=0;i<s.size();i++){steps++;count+=s.get(i);if(steps==m){if(count==d){total++;}// Instead of resetting, slide the windowcount-=s.get(i-m+1);// remove oldest elementsteps--;// shrink window by 1}}returntotal;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Subarray Division 1
You are viewing a single comment's thread. Return to all comments →
Java - O(n)