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.
Number Line Jumps
Number Line Jumps
Sort by
recency
|
3901 Discussions
|
Please Login in order to post a comment
i limit permutation on python
Typescript: if(v1 <= v2) return "NO"; const hasSameLocation = (x2 - x1)%(v1 - v2) === 0; return hasSameLocation ? "YES" : "NO";
java
function kangaroo(x1, v1, x2, v2) { // Write your code here
}
Typescript solution:
We can compose the problem as an algebraic expression: x1 + (j * v1) = x2 + (j * v2) where j is the number of jumps. The result line below is reducing the above formula to solve for j. For j to be valid in our problem, it has to be a positive whole number which we check within our if statement.