Sort by

recency

|

3910 Discussions

|

  • + 0 comments

    Here is my c++ solution, you can have the explanation here : https://youtu.be/bRVVCCmXN0Y

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

    //Java Code if(v2>=v1) { return "NO"; } else { if((x2-x1)%(v1-v2)==0) { return "YES"; } else { return "NO"; } }

  • + 1 comment
    import sys
    
    
    def kangaroo(x1, v1, x2, v2):
        if v2>=v1:
            return "NO"
        else:
            if (x2-x1)%(v1-v2)==0:
                return "YES"
            else:
                return "NO"
    
    if __name__ == '__main__':
      x1,v1,x2,v2 = list(map(int,input().strip().split(' ')))
      result = kangaroo(x1, v1, x2, v2)
      print(result)
    
  • + 0 comments

    char* kangaroo(int x1, int v1, int x2, int v2) { while (1) { // Conditions where the kangaroos cannot meet if ((x1 > x2 && v1 > v2) || (x1 < x2 && v1 < v2) || (x1 != x2 && v1 == v2)) { return "NO"; }

        // Update positions
        x1 += v1;
        x2 += v2;
    
        // Check if they meet
        if (x1 == x2) {
            return "YES";
        }
    }
    

    }

  • + 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';
    }