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){/* n: the number of pages in the book p: the page number to turn to */constpageTurns=Math.floor(p/2);consttotalTurns=Math.floor(n/2);/* Returns the total number of page turns it takes to get to a page or how many it requires if starting from the back */returnMath.min(pageTurns,totalTurns-pageTurns);}
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 JavaScript solution: