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.
Here is mine in Java, which I believe mine is only O(n).
staticintsolve(intn,int[]s,intd,intm){// Complete this functioninttotal=0;// the sumintlen=0;// the current length (window = length of m)intstart=0;// the starting index of the windowintcount=0;// the count for(intval:s){if(total<d&&len<m){total+=val;len++;}else{total=total-s[start]+val;start++;}if(total==d&&len==m)count++;}returncount;}
Subarray Division
You are viewing a single comment's thread. Return to all comments →
Here is mine in Java, which I believe mine is only O(n).