• + 1 comment

    Just solve it as a simple equation: x1 + (i * v1) = x2 + (i * v2) where i is the number of jumps. This becomes: i * ( v1 - v2) = x2 - x1. It will be 'YES' if i is a positive integer.

    function kangaroo(x1: number, v1: number, x2: number, v2: number): string {
        const dX = x2 - x1;
        const dV = v1 - v2;
        return (dX % dV == 0 && dX * dV >= 0) ? 'YES' : 'NO';
    }