Drawing Book

Sort by

recency

|

129 Discussions

|

  • + 0 comments

    Python 3 solution:

    def pageCount(n: int, p: int) -> int:
        p -= p % 2
        return min(n - p, p) // 2
    
    
    pageCount=lambda n,p:min(p//2,n//2-p//2)  # 40
    
  • + 0 comments
    def pageCount(n, p):
        # Write your code here
        if (n == 1 or n==p):
            return 0
        if (n % 2 > 0 and p == n-1):
            return 0
        midpage1, midpage2 = int(n/2), int(n/2) + 1
        page_counter = 0
        if (p <= midpage1):
            start = 1
            while (start < p):
                start += 2
                page_counter += 1
        elif (p >= midpage2):
            start = n-1
            if (start==p):
                return 1
            while (start > p):
                start -= 2
                page_counter += 1
        return page_counter
    
  • + 0 comments

    My rust solution:

    fn pageCount(n: i32, p: i32) -> i32 {
        (n/2 - p/2).min(p/2)
    }
    
  • + 1 comment

    Does test case 26 contain an error? Input is n = 6, p = 5 but expects the output to be 1. It should be 0 right?

  • + 0 comments
    def pageCount(n, p):
        return min(p//2, (n // 2) - (p // 2))