• + 0 comments

    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.

    let result = (x2 - x1) / (v1 - v2);
    
    if (result > 0 && result % 1 === 0)
        return "YES";
    else
        return "NO";