Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save daubattu/519e453c5dee02688ab96e49aa814287 to your computer and use it in GitHub Desktop.
Save daubattu/519e453c5dee02688ab96e49aa814287 to your computer and use it in GitHub Desktop.
[Hackerrank] Solution of Drawing Book in JavaScript
function pageCount(n, p) {
/*
* Write your code here.
*/
const pageFromStart = Math.floor(p/2);
const pageFromEnd = Math.ceil(((n % 2 !== 0 ? n - 1 : n) - p)/2);
return Math.min(pageFromStart, pageFromEnd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment