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.
Explanation: we have to print yes iff { x1+v1 x n= x2+v2 x n }
we have constraint that x1< x2 so =>
( v1-v2 )n=x2-x1 =>
n=(x2-x1)/(v1-v2)................n must be positive so v1>v2 and n is whole so the remainder should be 0
hence the code is as follows:
defkangaroo(x1,v1,x2,v2):# Write your code hereif(v1>v2and((x2-x1)%(v1-v2)==0)):return("YES")else:return('NO')
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 →
Explanation: we have to print yes iff { x1+v1 x n= x2+v2 x n } we have constraint that x1< x2 so => ( v1-v2 )n=x2-x1 => n=(x2-x1)/(v1-v2)................n must be positive so v1>v2 and n is whole so the remainder should be 0 hence the code is as follows: