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.
publicstaticintworkbook(intn,intk,List<int>arr){intpage=1;intchProb=0;intspecial=0;foreach(intiinarr){intproblems=i;// cant change iterated values so assing to new varwhile(problems>0){// get problems in page, the min of k and left over problemsintpgProbs=Math.Min(k,problems);// Add problems from the page to the chapter problemschProb+=pgProbs;// Check if the problems worked are specialif(page>=(chProb-pgProbs+1)&&page<=chProb)special++;// Found a special problem// Subtrack the problems worked from the problems in the chapterproblems-=pgProbs;// Next pagepage++;}// Reset chapter problemschProb=0;}// return special countreturnspecial;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lisa's Workbook
You are viewing a single comment's thread. Return to all comments →
In C#