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.
The problem asks whether they will meet at a particular point after same number of jumps.
Distance moved after 'y' jumps
kangaroo1 d1 = x1 + v1 * y.
kangaroo2 d2 = x2 + v2 * y.
'y' must be same for both kangaroos.
d1 = d2.
x1 + v1 * y = x2 + v2 * y.
rearanging the above equation we get
y = (x2 - x1)/(v1 - v2).
y is number of jumps which must be a positive integer. Therefore which implies that x2-x1 is divisible by v1-v2. This is how the equation has evolved.
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 →
The problem asks whether they will meet at a particular point after same number of jumps. Distance moved after 'y' jumps kangaroo1 d1 = x1 + v1 * y. kangaroo2 d2 = x2 + v2 * y. 'y' must be same for both kangaroos. d1 = d2. x1 + v1 * y = x2 + v2 * y. rearanging the above equation we get y = (x2 - x1)/(v1 - v2). y is number of jumps which must be a positive integer. Therefore which implies that x2-x1 is divisible by v1-v2. This is how the equation has evolved.