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.
- Prepare
- Algorithms
- Implementation
- Drawing Book
- Discussions
Drawing Book
Drawing Book
+ 87 comments Extremely simple solution in Python
#!/bin/python import sys n = int(raw_input().strip()) p = int(raw_input().strip()) print min(p/2,n/2-p/2)
+ 10 comments Hello friends,
In this video tutorial, I have explained hackerrank drawing book solution algorithm. hackerrank drawing book problem can be solved by using mathematics. The complexity of drawing book hackerrank solution is O (1)
If interested to know more about the generic algorithm in details-
click here for the video explanation of generic algorithm with complexity analysis.
or you can click on the image too to follow youtube tutorial.
Here is the working solution:-
source code :
static int pageCount(int n, int p) { int totalPageTurnCountFromFront = n / 2; int targetPageTurnCountFromFront = p / 2; int targetPageTurnCountFromBack = totalPageTurnCountFromFront - targetPageTurnCountFromFront; return Math.min(targetPageTurnCountFromFront, targetPageTurnCountFromBack); }
Would really appreciate your feedback like, dislike , comment etc. on my video.
Do not forget to upvote, if you find it useful.
+ 24 comments My solution in C...Hope it helps!!!
#include<stdio.h> int main() { int n=0,p=0,min; scanf("%d",&n); scanf("%d",&p); min=(n/2)-(p/2); if(min>p/2) min=p/2; printf("%d",min); return 0; }
+ 10 comments My JavaScript solution:
function pageCount(n, p) { /* n: the number of pages in the book p: the page number to turn to */ const pageTurns = Math.floor(p / 2); const totalTurns = Math.floor(n / 2); /* Returns the total number of page turns it takes to get to a page or how many it requires if starting from the back */ return Math.min(pageTurns, totalTurns - pageTurns); }
+ 2 comments Input for test case #26 has to be on two lines.
Load more conversations
Sort 1523 Discussions, By:
Please Login in order to post a comment