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.
/* First Page and Last Page*/if(p==n||p==1){return0;}elseif(p==1&&n%2==0){// First Page onlyreturn0;}elseif(p==n-1&&n%2==0){//Last Page onlyreturn1;}else{// In between pagesletcount=0;if(p<=n/2){// page less than mid page// search from leftleti=1;letcount=0while(i<=p){if(i!=p)count++;i+=2;}returncount;}else{// page greater than mid page//search from right.letj=n-1;letcount=0;while(p<=j){if(p!=j)count++;j-=2;}returncount;}}
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 →
Javascript: