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.
public static int pageCount(int n, int p) {
// Write your code here
int firstStart = 0;
int lastStart = 0;
for (int i = 0; i < n; i++) {
firstStart++;
if (i == p) {
break;
}
}
for (int i = n; i >= 0; i--) {
lastStart++;
if (i == p) {
break;
}
}
int f;
int l;
if (n % 2 == 0) {
f = (firstStart / 2);
l = (lastStart / 2);
} else {
f = (firstStart / 2);
l = (lastStart / 2) - 1;
}
return Math.min(f, l);
}
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(8)