• + 0 comments

    Solution in C

    char* kangaroo(int x1, int v1, int x2, int v2) {
        
        char *s = malloc (10 * sizeof(char));
        int relativeSpeed;
        
        //if speed of kangaroo 1 is slower or equal to kangaroo 2,    they will never meet
        if (v1 <= v2) {
            s = "NO";
        }
        else {
            //finding relative speed
            relativeSpeed = x2 - x1;
            
            //If relativeSpeed % (v1 - v2) == 0, then the kangaroos will meet at some future time.
            if (relativeSpeed % (v1 - v2) == 0) {
                s = "YES";
            }
            else {
                s = "NO";
            }
        }
        
        return s;
        free(s);
    }