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.
@maximshen, why do we need to check this condition(x2-x1)/(v1-v2) if we initially find out that v2≧v1 and there is no solution.
lets undarstad this with example:
take minimum value of x1 i.e, x1=0 so we can take x2=1 because according to problem statement x2 is always greater than x1.
now if v1 and v2 bothe are equal then x1 will never catch x2 because of same speed, in this case no solution and print "no".
so we can proceed further for solution, only when v2 is less than v1, hence v1-v2 is always positive integer. so there is no need for cheking (x1-x2)/(v1-v2).
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 →
@maximshen, why do we need to check this condition(x2-x1)/(v1-v2) if we initially find out that v2≧v1 and there is no solution. lets undarstad this with example: take minimum value of x1 i.e, x1=0 so we can take x2=1 because according to problem statement x2 is always greater than x1. now if v1 and v2 bothe are equal then x1 will never catch x2 because of same speed, in this case no solution and print "no". so we can proceed further for solution, only when v2 is less than v1, hence v1-v2 is always positive integer. so there is no need for cheking (x1-x2)/(v1-v2).