We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Drawing Book
- Discussions
Drawing Book
Drawing Book
Sort by
recency
|
215 Discussions
|
Please Login in order to post a comment
short c++ solution. the main idea is that we can calculate how many pages to turn to get number 'x' by turning 'x//2' pages (divide with rounding down e.g. 5//2 = 2). It's because on every display of 2 pages there are 2 consecutive pages e.g. (2,3), (3,4) etc. All we gotta do is just see if we can get from 0->p by turning p//2 pages or from n->p which is n//2-p//2.
C#
Javascript
C# SOLUTION
if (p / 2 <= (n % 2 == 0 ? (n+1-p) / 2 : (n-p) / 2)) { return p/2; } return n % 2 == 0 ? (n+1-p) - 2 : (n-p) / 2;
Here is - HackerRank Drawing Book problem solution