Sort by

recency

|

2070 Discussions

|

  • + 0 comments

    "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."

    What does that bolded part even mean?

  • + 0 comments

    1->2,3->4,5->6

    **o. front flips-> ** * new page starting with even number : if p is even then p/2=front flips * if p is odd then p-1/2=front flips

    ** o. from back ->** * if page even: n-p/2=back flips * if page is odd: n-p-1/2=back flips

  • + 0 comments

    Here's the solution in python:

    def pageCount(n, p):
    # Calculate turns from front and back
    front_turns = p // 2
    back_turns = (n // 2) - (p // 2)
    
    # Return the minimum of the two
    return min(front_turns, back_turns)
    
  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/1T650YeAwRI

    int pageCount(int n, int p) {
        return min(p/2, n/2-p/2);
    }
    
  • + 0 comments

    Intuative using loop

    def pageCount(n, p):
        
        # Write your code here
        start_count = 0
        end_count = 0
        start = 1
        end = n
        
        # From start
        i = 1
        while i <= end:
            
            if i >= p:
                break
            
            i = i + 2
            start_count += 1
        
        # From end
        if end % 2 == 0:
            j = end
        else:
            j = end - 1
        while j >= start:
            
            if j <= p:
                break
                
            j = j - 2
            end_count += 1
            
        return min(start_count, end_count)