Sort by

recency

|

2119 Discussions

|

  • + 0 comments

    Mi solución en Python 3:

    def pageCount(n, p):
        # Write your code here
        from_start = p // 2 
        from_end = (n // 2) - (p // 2) 
        return min(from_start, from_end)
    
  • + 0 comments

    Fastest one liner:

    #include <iostream>
    #include <climits> 
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    
        int n, p; 
        cin >> n >> p; 
    
        cout << min(p >> 1, ((n | 1) - p) >> 1) << endl; 
        return 0; 
    }
    
  • + 0 comments

    Python 3 Solution:

    def pageCount(n, p):
        # Write your code here
        c_s = p // 2
        c_e = (n // 2) - c_s
        res = min(c_s, c_e)
        return res
    
  • + 0 comments

    "The last page may only be printed on the front, given the length of the book."

    ...no, it can be either side of the page, and even is so in the basic examples given

  • + 0 comments

    return min((p)//2,(n-p+p%2)//2)