• + 0 comments

    Most of the solutions here have oversimplified one fact that if the number of book pages are even for example n is 8 and the user wants to turn to an odd page (For example, take p = 5), their solutions will break because they have hardcoded to return 1. I am sharing my solution in C#:

            int minPages = 0;
            if((n-p)<p)
            {
                minPages = (n%2==0&&p%2!=0)?((n-p)/2+1):((n-p)/2);
                return minPages;  
            }
            else
                return p/2;