Lisa’s Workbook – Hackerrank Challenge – Java Solution
This is the java solution for the Hackerrank problem – Lisa’s Workbook – Hackerrank Challenge – Java Solution.
Source – Ryan Fehr’s repository.
//Problem: https://www.hackerrank.com/challenges/lisa-workbook //Java 8 /* page number = 1 problem number 4 (4 - k) = 1 3 < 4 will be on page 1 -> is 1 equivalent to 4 - 3 , - 2, -1 loop over remainder until remainder < 0 handle the0) //Loop through all problems for this chapter { int pageProblems = problems; pageProblems -= k; if(pageProblems > 0) //Determine if there are enough problems left for a full page {pageProblems = k;} else //If not just run the remaining problems {pageProblems += k;} //System.out.println("adding "+ pageProblems +" problems to a page"); while(pageProblems > 0) //While we still have problems to put on the current page { //System.out.println("Problem "+currentProblem+" was put on page "+ pageNumber); if(pageNumber == currentProblem) //If the current problem we are adding to a page is the same index as the { //page increment specialProblems specialProblems++; } currentProblem++; pageProblems--; } problems -= k; //Remove the problems we have added to the page pageNumber++; //Move to next page } } System.out.println(specialProblems); } }