Number Line Jumps

Sort by

recency

|

125 Discussions

|

  • + 3 comments

    I'm confused by this one. 0 3 4 2 So, the steps should be as follows... 0 3 6 9 for kangaroo 1 4 6 8 10 for kangaroo 2

    The expected answer is YES, but the steps don't line up. The question reads like the kangaroos must jump at the same time.

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

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

        return "NO";
    

    }

    }

  • + 0 comments

    Thought about as just intersecting lines.

    def kangaroo(x1, v1, x2, v2):
        if v2 >= v1:
            return "NO"
        xint = (x2 - x1) / (v1 - v2)
        if xint % 1 != 0:
            return "NO"
        return "YES"
    
  • + 0 comments

    Python3 1 liner:

    def kangaroo(x1, v1, x2, v2):
        return 'YES' if v1 > v2 and (x2-x1) % (v1-v2) == 0 else 'NO'
        
        #general case (no constain x1 < x2)
        # if v1 == v2:
        #     return 'YES' if x1 == x2 else 'NO'
        # return 'YES' if (x2-x1) / (v1-v2) >= 0 and (x2-x1) % (v1-v2) == 0 else 'NO'