• + 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)