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.
Doesn't handle the case where 2 starts ahead and 1 never catches up (e.g., 0 2 5 3). You need to ensure that the sign of the position difference and the sign of the velocity difference are opposite, i.e., the velocity will overcome the position difference rather than increase it:
Number Line Jumps
You are viewing a single comment's thread. Return to all comments →
Doesn't handle the case where 2 starts ahead and 1 never catches up (e.g., 0 2 5 3). You need to ensure that the sign of the position difference and the sign of the velocity difference are opposite, i.e., the velocity will overcome the position difference rather than increase it:
print("YES" if (x2 - x1) * (v2 - v1) < 0 and (x2 - x1) % (v2 - v1) == 0 else "NO")
This also short-circuits a divide-by-zero error if the velocity difference is zero (e.g., 43 2 70 2).