Hackerrank's Problem Solving solutions( Bill Division, Sales by Match, Drawing Book ) :
Problem 19: Bill Division
Solution: (in c++)
( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder)
This code is simple. There's no need for any explanation.
Problem 20: Sales by Match
Solution: (in c++)
( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder)
This code is simple. There's no need for any explanation.
Problem 21: Drawing Book
Solution: (in c++)
( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder)
This question is easy. First we will check whether the no. of pages in the book is even or odd. The first if statement tests that n=even. Now we want to determine from where to start start searching the page i.e from the front or back (it can be easily done by comparing the distance of page to be searched i.e p from first page and last page ) therefore , we will use (abs(p-1)<=abs(p-n)) which means we will start from the front page. It's else means we will start from the last page. Similarly else of the first statement means the no. of pages are odd and then we will again see from where to start searching i.e from front or back. It took me hours to solve this question but when i saw the discussion section i was really shocked and amazed also as this question was wrapped in only 3 lines with no explanation how. This solution below is famous in the discussion section -
I also don't know how it is working. If you find out the logic , please let me know in the comment section below.
Guys , if you have any queries or need more explanation for something , comment below!
Comments
Post a Comment