• + 0 comments

    Solution in C++:

    string kangaroo(int x1, int v1, int x2, int v2) {
        
        if(x1 == x2 && v1 == v2)
            return "YES";
        else
        {
            if(v1 == v2)
                return "NO";
            else
            {
                if((x1 - x2)%(v2 - v1))
                {
                    return "NO";
                }
                else
                {
                    if((x1 - x2)*(v2 - v1) > 0)
                        return "YES";
                    else
                        return "NO";
                }
            }
        }
    }