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.
its breaking from the loop IF it finds the answer..
if (k1!=k2)
it will never break out until i >= 10000
which is a waste of memory, if you only need like 200 loops for example. or with all the "test cases" what if you need 20,000 loops?
i have everything inside of a while with 1 if, 2 else if and an else.
Thats it. Then its dymaicaly looping and not static
Number Line Jumps
You are viewing a single comment's thread. Return to all comments →
its breaking from the loop IF it finds the answer.. if (k1!=k2) it will never break out until i >= 10000 which is a waste of memory, if you only need like 200 loops for example. or with all the "test cases" what if you need 20,000 loops?
i have everything inside of a while with 1 if, 2 else if and an else. Thats it. Then its dymaicaly looping and not static
string ans = ""; while (1) { x1 += v1;
x2 += v2;
if (v1 >= v2 && x1 > x2) {ans = "NO"; break;} else if (v2 >= v1 && x2 > x1) {ans = "NO"; break;} else if (abs(x1-x2) % abs(v1-v2) != 0) {ans = "NO"; break;} else {ans = "YES"; break;} } return ans;
System.out.print("YES"); System.exit(0); } } System.out.print("NO");