Posts

Showing posts from January, 2019

Drawing Book - HackerRank.

Image
NOTE:   If you are copying my code then its an advice to you to copy it after downloading it to avoid any kind of compilation error its link is available at the bottom of the source code. Brie’s Drawing teacher asks her class to open their books to a page number. Brie can either start turning pages from the front of the book or from the back of the book. She always turns pages one at a time. When she opens the book, page   is always on the right side: When she flips page  , she sees pages   and  . Each page except the last page will always be printed on both sides. The last page may only be printed on the front, given the length of the book. If the book is   pages long, and she wants to turn to page  , what is the minimum number of pages she will turn? She can start at the beginning or the end of the book.

Save the Prisoner! - HackerRank.

Image
NOTE:  If you are copying my code then its an advice to you to copy it after downloading it to avoid any kind of compilation error its link is available at the bottom of the source code. A jail has a number of prisoners and a number of treats to pass out to them. Their jailer decides the fairest way to divide the treats is to seat the prisoners around a circular table in sequentially numbered chairs. A chair number will be drawn from a hat. Beginning with the prisoner in that chair, one candy will be handed to each prisoner sequentially around the table until all have been distributed. The jailer is playing a little joke, though. The last piece of candy looks like all the others, but it tastes  awful . Determine the chair number occupied by the prisoner who will receive that candy. For example, there are   prisoners and   pieces of candy. The prisoners arrange themselves in seats numbered   to  . Let's suppose two is drawn from the hat. Prisoners receive c