Number Line Jumps

Sort by

recency

|

129 Discussions

|

  • + 0 comments

    Yet, another poorly worded problem.

  • + 0 comments

    Rust 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

    fn number_line_jumps(x1: i32, v1: i32, x2: i32, v2: i32) -> String {
        //Time complexity: O(1)
        //Space complexity (ignoring input): O(1)
        if x1 == x2 {
            return "YES".to_string();
        }
        if v1 == v2 {
            return "NO".to_string();
        }
    
        let relative_speed = v2 - v1;
        let initial_distance = x1 - x2;
        let jumps = initial_distance as f32 / relative_speed as f32;
        if jumps == jumps.abs().floor() {
            return "YES".to_string();
        }
    
        "NO".to_string()
    }
    
  • + 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"
    
  • + 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"
    
  • + 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.