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.
- Prepare
- Algorithms
- Implementation
- Drawing Book
- Discussions
Drawing Book
Drawing Book
Sort by
recency
|
2052 Discussions
|
Please Login in order to post a comment
Here is my c++ solution, you can watch the explanation here : https://youtu.be/1T650YeAwRI
i made solution using python!
in python I use 2 loop
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.
int pageCount(int n, int p) { return min(n / 2 - p / 2, p / 2); }