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.
def kangaroo(x1, v1, x2, v2):
#check if both vectors are same
if v1==v2:
return 'NO'
else:
#verify if the intervel where the kangaroos are meeting is grater than 0 as the vectors are moving positively
i = math.ceil(((x1-x2)/(v2-v1)))
if i > 0 and (x1 + v1*i) == (x2 + i*v2) :
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 →
def kangaroo(x1, v1, x2, v2): #check if both vectors are same if v1==v2: return 'NO' else: #verify if the intervel where the kangaroos are meeting is grater than 0 as the vectors are moving positively i = math.ceil(((x1-x2)/(v2-v1))) if i > 0 and (x1 + v1*i) == (x2 + i*v2) : return 'YES' else: return "NO"