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.
This question is flawed, for one of the test cases they assert that n = 5 and p = 4 should yield 0 pages flipped. But a book with 5 pages has an unused or blank page as the 6th page. If one were to start from the back of the book, having only flipped the back cover and no pages, they would be looking at the 6th page. To view the 4th page would require 1 flip, exposing pages 4 and 5. Thus n = 5 and p = 4 should yield 1?
"Each page except the last page will always be printed on both sides. The last page may only be printed on the front, given the length of the book." - This is an example where the last page, page 5 is printed on the front, given the length of the book, n = 5.
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 →
This question is flawed, for one of the test cases they assert that n = 5 and p = 4 should yield 0 pages flipped. But a book with 5 pages has an unused or blank page as the 6th page. If one were to start from the back of the book, having only flipped the back cover and no pages, they would be looking at the 6th page. To view the 4th page would require 1 flip, exposing pages 4 and 5. Thus n = 5 and p = 4 should yield 1?
"Each page except the last page will always be printed on both sides. The last page may only be printed on the front, given the length of the book." - This is an example where the last page, page 5 is printed on the front, given the length of the book, n = 5.