Sort by

recency

|

3971 Discussions

|

  • + 0 comments

    This is my code in js:

    function kangaroo(x1, v1, x2, v2) {
        // Write your code here
        // constraint given x2 >x1
        let dist = x2-x1;
            
        while(dist>0){
        x1 += v1;
        x2 += v2;
        
        if(x1===x2) return 'YES';   
        else if ((x2-x1)>=dist)return 'NO';
        else dist = x2 - x1;
        }   
        return 'NO';
    }
    
  • + 0 comments

    THIS IS MY PYTHON CODE:

    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    #
    # Complete the 'kangaroo' function below.
    #
    # The function is expected to return a STRING.
    # The function accepts following parameters:
    #  1. INTEGER x1
    #  2. INTEGER v1
    #  3. INTEGER x2
    #  4. INTEGER v2
    #
    
    def kangaroo(x1, v1, x2, v2):
        if v1 == v2:
            return "YES" if x1 == x2 else "NO"
        if (x2 - x1) * (v1 - v2) < 0:
            return "NO"
        if (x2 - x1) % (v1 - v2) == 0:
            return "YES"
        return "NO"
    
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        first_multiple_input = input().rstrip().split()
    
        x1 = int(first_multiple_input[0])
        v1 = int(first_multiple_input[1])
        x2 = int(first_multiple_input[2])
        v2 = int(first_multiple_input[3])
    
        result = kangaroo(x1, v1, x2, v2)
    
        fptr.write(result + '\n')
    
        fptr.close()
    
  • + 0 comments

    Nowhere in the problem statement does it say that time must be an integer for a solution to be accepted. However it seems the solution assumes this since the testcase: 21 6 47 3 has a meeting point at the integer 71 but a non-integer time and is meant to return "NO".

    How to report this? This should either return "YES" as the solution, or it should be made clear that the solution should also be for integer time.

  • + 0 comments

    ` # - The one who starts behind is too slow to catch up # - OR the one ahead is too fast to ever be caught # - n is not an integer > They never land on the same spot return 'YES' if n >= 0 else 'NO' return 'NO'

    #

  • + 1 comment

    Python: O(1) solution

    def kangaroo(x1, v1, x2, v2):
        # Write your code here
        
        if v1 <= v2:
            return "NO"
            
        if v1 % v2 == 0 and (x2 % x1 == 0):
            return "YES"
            
        n_steps = (x2 - x1) / (v1 - v2)
        
        if n_steps % 1 == 0:
            return "YES"
        
        return "NO"