Sort by

recency

|

3921 Discussions

|

  • + 0 comments
    func kangaroo(x1 int32, v1 int32, x2 int32, v2 int32) string {
        // Write your code here
    		// k1 = x1 + m.v1
    		// k2 = x2 + m.v2
    		// if k1 = k2 then m > 0 and m is an integer
        numberOfJump := float32(x2 - x1) / float32(v1 - v2)
        if numberOfJump > 0 && numberOfJump - float32(int32(numberOfJump)) == 0 {
            return "YES"
        }
        
        return "NO"
    }
    
  • + 0 comments
        for jump in range(0,100000):
            dist_1=x1+jump*v1
            dist_2=x2+jump*v2
            if dist_1==dist_2:
                print("JUMP: {}".format(jump))
                return "YES"
            elif (v2>v1 and x2>x1+v1) or (v1>v2 and x1>x2+v2):
                continue
            else:
                continue
        return "NO"
    
  • + 1 comment
        int round = (x1+v1)*(x2+v2);
        for (int i = 0; i < round; i++) {
            if(x1+v1 == x2+v2){
                return "YES";
            }
            x1 +=v1;
            x2 +=v2;
        }
        return "NO";   
    
  • + 0 comments
    String NO = "NO"; String YES = "YES";
    boolean faster = (x1 >= x2 && v1 > v2) || (x2 >= x1 && v2 > v1);
    boolean late = (v1 == v2 && x2 > x1) || (v1 == v2 && x1 > x2);
    if(faster || late ) return NO;
    if(x2 > x1) {
    return ((x2 - x1) % (v1 - v2) == 0) ? YES : NO;
    } else {
    return ((x1 - x2) % (v2 - v1) == 0) ? YES : NO;
    }
    
  • + 0 comments

    My code my not be the fastest but it gets the job done! Basically, if the kangaroo that is behind has a higher speed, then we go to the next jump and check if they are at the same position. If the kangaroo that is ahead has the higher speed, then we return "NO".

    def kangaroo(x1, v1, x2, v2):
        pos = [x1, x2]
        speed = [v1, v2]
        while speed[pos.index(min(pos))] > speed[pos.index(max(pos))]:
            pos[0] += speed[0]
            pos[1] += speed[1]
            if pos[0] == pos[1]:
                return "YES"
        return "NO"