Number Line Jumps

  • + 0 comments

    Python best solution

    If you’re looking for solutions to the 3-month preparation kit in either Python or Rust, you can find them below: my solutions

    def number_line_jumps(x1, v1, x2, v2):
        # Time complexity: O(1)
        # Space complexity (ignoring input): O(1)
        if x1 == x2:
            return "YES"
        if v1 == v2:
            return "NO"
    
        relative_speed = v2 - v1
        initial_distance = x1 - x2
        jumps = initial_distance / relative_speed
    
        if jumps == abs(int(jumps)):
            return "YES"
    
        return "NO"