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
|
2110 Discussions
|
Please Login in order to post a comment
Here is Drawing Book solution in Python, Java, C++, C and Javascript programming - https://programmingoneonone.com/hackerrank-drawing-book-problem-solution.html
Page Turns in Rust: Solving the Book Page Count Problem in O(1)
This function computes the minimum number of page turns needed to reach page p in a book of n pages. The student can start turning pages either from the front (page 1) or from the back (page n).
Key idea:
Number of page turns from the front: from_front = p/2 Because every page turn advances 2 pages (left + right).
Number of page turns from the back: from_back=n/2−p/2 Here n/2 is the total number of “spreads” in the book, and p/2 is how many spreads we’ve passed from the front.
Time complexity: The function performs only a couple of integer operations and a conditional -->O(1) time.
Space complexity: It uses only fixed scalar variables, no extra data structures --> O(1) space.
There are two types of people: Type 1:
Simple Python Solution: