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.
if (v2 >= v1) {
return "NO";
}
//initial distance
let d1 = x2 - x1;
//distance after 1 jump
let d2 = (x2 + v2) - (x1 + v1);
//diff gives how much closer x1 gets after each jump
let x = d1 - d2;
//if initial distance can be evenly divided by how
//close x1 gets each jump, they will eventually meet.
if (d1 % x === 0) {
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 →
Javascript O(1)