Sort by

recency

|

3936 Discussions

|

  • + 0 comments

    GOLANG - Simple Solution:

    func kangaroo(x1 int32, v1 int32, x2 int32, v2 int32) string {
        if v1 <= v2 {
            return "NO"
        }
        if (x2-x1)%(v1-v2) == 0 {
            return "YES"
        }
        return "NO"
    }
    
  • + 0 comments

    Here is my c++ solution, you can have the explanation here : https://youtu.be/bRVVCCmXN0Y

    string kangaroo(int x1, int v1, int x2, int v2) {
        if(v1 > v2 && (x2-x1) % (v1-v2) == 0) return "YES";
        return "NO";
    }
    
  • + 0 comments
        public static string kangaroo(int x1, int v1, int x2, int v2)
        {
            if(v1 == v2 & x1 == x2) return "YES";
            if(v1 == v2 & x1 != x2) return "NO";
            if(v1 > v2 & x1 >= x2) return "NO";
            if(v2 > v1 & x2 >= x1) return "NO";
            int vFinal = v1 - v2;
            int xFinal = x1 - x2;
            int mod = xFinal % vFinal;
            if(mod == 0) return "YES";
            return "NO";
        }
    
  • + 0 comments

    string kangaroo(int x1, int v1, int x2, int v2) {

        if(v1 > v2)
        {
            // Time to meet = (x2-x1)/(v1 - v2)
            // The meeting time should be rational integer
            if((x2-x1) % (v1 - v2)== 0)            
                return "YES";
        }
    
    return "NO";
    

    }

  • + 2 comments

    I am struggling to understand why on earth this usecase expects YES: x1 = 0 x2 = 3 v1 = 4 v2 = 2 If the first jump gets x1 at position 4 and x2 at position 5 then in teh second jump x1 surpass x2 and stays ahead from there onwards.