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.
java :- In this 2 for loops are there in which for every iteration you turn a page until u find the "p". for both 'from the front' and 'from the last' page of the book.
it seems a bit long , but very easy to understand for freshers...
publicstaticintpageCount(intn,intp){// Write your code hereintff=0;intfl=0;intindex=0;for(inti=0;i<=n;i+=2){index=i/2;if(p==1){ff=0;}elseif(p==n){fl=0;}elseif((p/2==index)){break;}else{ff++;}}for(inti=n;i>=0;i-=2){index=i/2;if((p/2==index)){break;}else{fl++;}}if(ff<=fl){returnff;}else{returnfl;}}
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 :- In this 2 for loops are there in which for every iteration you turn a page until u find the "p". for both 'from the front' and 'from the last' page of the book. it seems a bit long , but very easy to understand for freshers...