HackerRank 'Drawing Book' Solution

Martin Kysel · July 26, 2020

Short Problem Definition:

Brie’s Drawing teacher asks her class to open their books to a page number. Brie can either start turning pages from the front of the book or from the back of the book. She always turns pages one at a time.

Drawing Book

Complexity:

time complexity is O(1)

space complexity is O(1)

Execution:

Think of this as a 0-indexed book. Use integer division.

Solution:
def solve(n, p):
    last_letter = n // 2
    goal_letter = p // 2
    return min(goal_letter, last_letter-goal_letter)

Twitter, Facebook

To learn more about solving Coding Challenges in Python, I recommend these courses: Educative.io Python Algorithms, Educative.io Python Coding Interview.