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.
publicstaticintpageCount(intn,intp){// Write your code hereintcurrentLeaf=0;intcountLeaf=0;intminimum=0;for(intpage=currentLeaf;page<=n;page++){if(currentLeaf==p||currentLeaf+1==p)break;currentLeaf+=2;countLeaf++;}minimum=countLeaf;currentLeaf=n%2==0?n+1:n;countLeaf=0;for(intpage=currentLeaf;page>0;page--){if(currentLeaf==p||currentLeaf-1==p)break;currentLeaf-=2;countLeaf++;}returnminimum>countLeaf?countLeaf:minimum;}
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 →
Java