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.
functionpageCount(n,p){// Write your code here// calculate book front and back pages differencesconstfrontDiff=p-1;// calculate backDiff based on even or odd page numbers (extract 1 or 0)constbackDiff=n-p-(n%2);// calculate turns by dividing difference by 2constfrontTurns=frontDiff/2;constbackTurns=backDiff/2;// get min turns amount and round it (0.5 => 1, 1.5 => 2 and etc)returnMath.round(Math.min(frontTurns,backTurns));}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Drawing Book
You are viewing a single comment's thread. Return to all comments →
My solution in JS: