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.
The reason for this is that if the greater velocity has already exceeded the smaller velocity in distance there is no way the smaller velocity can ever catch up or meet the greater velocity. However, some of the test cases timeout because of this condition.
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 →
The condition I used for the for loop was
for(int n = 1; !((v1>v2 && n*v1 + x1 > n*v2+x2)|| v1
The reason for this is that if the greater velocity has already exceeded the smaller velocity in distance there is no way the smaller velocity can ever catch up or meet the greater velocity. However, some of the test cases timeout because of this condition.