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.
While this works, it works because you know that Kangaroo 2 is ahead of Kangaroo 1, and presumably you've excluded the impossible case (i.e. Kangaroo 2 has a greater jump distance than Kangaroo 1, as noted in the description).
As an enhancement, if you use the absolute values of the difference in position and the absolute value of the difference in jump rates (after excluding the case of the kangaroo in front having a greater jump distance than the kangaroo behind, for which you should immediately return NO), you can have either kangaroo in front of each other and it still works.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Number Line Jumps
You are viewing a single comment's thread. Return to all comments →
While this works, it works because you know that Kangaroo 2 is ahead of Kangaroo 1, and presumably you've excluded the impossible case (i.e. Kangaroo 2 has a greater jump distance than Kangaroo 1, as noted in the description).
As an enhancement, if you use the absolute values of the difference in position and the absolute value of the difference in jump rates (after excluding the case of the kangaroo in front having a greater jump distance than the kangaroo behind, for which you should immediately return NO), you can have either kangaroo in front of each other and it still works.