Number Line Jumps

  • + 0 comments
    #python solution
    def kangaroo(x1, v1, x2, v2):
        #tests if intersection is not possible
        if (v1 == v2 and x1 != x2) or v2 > v1: 
            return "NO"
            
        k1 = x1
        k2 = x2
    		
        #tests if intersection will happen at an integer
        while k1 < k2:
            k1 += v1
            k2 += v2
            if k1 > k2:
                return "NO"
                
        return "YES"