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<int>s,intd,intm){// Create counter for found segmentsintsegCount=0;// Loop through the list to find the segments// Since we're grabbing segments and don't want to// grab more than we can, only go till list length// minus the bday month (m)for(intx=0;x<=s.Count-m;x++){// Grab the segment and sum it// Grab from x (current pos) to x + m// i.e. 0 + (0 + 2) end range is exclusiveintsegSum=s[x..(x+m)].Sum();// Check if the sum equals the bday day// If so, add to the segment countif(segSum==d)segCount++;}// Return segment count;returnsegCount;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Subarray Division
You are viewing a single comment's thread. Return to all comments →
In C#