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.
I hope this helps someone who was confused as to why we needed to calculate the mod.
First of all, as @Mily94 pointed out this problem's solution could be solved using this simply equation:
x1 + (j * v1) = x2 + (j * v2) where 'j' is the number of jumps.
Simplifying the equation gives us this: j = (x2 - x1) / (v1 - v2)
and in order to figure out if 'j' is a whole number (i.e. if there exists a whole number of jumps that would allow our kangaroos to meet), we have to find out if the remainder of this division is 0, which requires the use of the modulo operator. I hope this makes sense.
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 →
I hope this helps someone who was confused as to why we needed to calculate the mod.
First of all, as @Mily94 pointed out this problem's solution could be solved using this simply equation:
Simplifying the equation gives us this: j = (x2 - x1) / (v1 - v2) and in order to figure out if 'j' is a whole number (i.e. if there exists a whole number of jumps that would allow our kangaroos to meet), we have to find out if the remainder of this division is 0, which requires the use of the modulo operator. I hope this makes sense.