• + 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"