Sort by

recency

|

3901 Discussions

|

  • + 0 comments
    def kangaroo(x1, v1, x2, v2):
        counter = 0
        while counter < 10000:
            x1+=v1
            x2+=v2
            counter+=1
            if x1 == x2:
                return "YES"
                break
            elif counter == 10000:
                return "NO"
    

    i limit permutation on python

  • + 0 comments

    Typescript: if(v1 <= v2) return "NO"; const hasSameLocation = (x2 - x1)%(v1 - v2) === 0; return hasSameLocation ? "YES" : "NO";

  • + 0 comments

    java

        public static String kangaroo(int x1, int v1, int x2, int v2) {
            double time = (double)(x1- x2) / (double)(v2 - v1);
            return time >= 0 && time % 1 == 0 ? "YES" : "NO";
        }
    
  • + 0 comments

    function kangaroo(x1, v1, x2, v2) { // Write your code here

    // Debug
    // 2081 8403 9107 8400
    
    let answer = "";
    let count = 0;
    
    let number  = (x1 + v1 + x2 + v2) * 10
    
    for( let i = 0; i <= number; i++){
    
      count += x1 + (i * v1) ===  x2 + (i * v2) ? 1 : 0;
    
    
    }
    
    answer = count > 0 ? "YES" : "NO"
    
    
    return answer
    

    }

  • + 0 comments

    Typescript solution:

    We can compose the problem as an algebraic expression: x1 + (j * v1) = x2 + (j * v2) where j is the number of jumps. The result line below is reducing the above formula to solve for j. For j to be valid in our problem, it has to be a positive whole number which we check within our if statement.

    let result = (x2 - x1) / (v1 - v2);
    
    if (result > 0 && result % 1 === 0)
        return "YES";
    else
        return "NO";