• + 2 comments

    I think it is better to solve it this way:

    string kangaroo(int x1, int v1, int x2, int v2) {
        // Complete this function
        // x1+m*v1=x2+mv2 => m=(x1-x2)/(v2-v1) , m is steps and
        //m should not be negetive and 
        //remainder should be zero
        int x=x1-x2;
        int v=v2-v1;
        if(v!=0){
            if(x%v==0 && x/v>0){
                return "YES";
            }else {return "NO";}
            
        }else {return "NO";}
        
    }
    

    It works