We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Number Line Jumps
  5. Discussions

Number Line Jumps

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 3631 Discussions, By:

recency

Please Login in order to post a comment

  • angel007lr
    2 days ago+ 0 comments
    string kangaroo(int x1, int v1, int x2, int v2) {
        
        for (int i=1; i <= 10000 ; i ++) {
            if ( x1 == x2 ){
                return "YES";
            }
            x1 = x1 + v1;
            x2 = x2 + v2;
        
        }
        return "NO";
    }
    
    0|
    Permalink
  • marcos_csca
    2 days ago+ 0 comments
    string kangaroo(int x1, int v1, int x2, int v2) {
        int i = 1;
    do {
    x1 = x1 + v1;
    x2 = x2 + v2;
    if(x1 == x2) return "YES";  
    i++;
    }while (i <= 10000);
    return "NO";
    }
    
    0|
    Permalink
  • shashwat100k
    2 days ago+ 0 comments

    include

    using namespace std;

    int main() { int x1, x2, v1, v2;

    // Input the values
    cin >> x1 >> v1 >> x2 >> v2;
    
    // Check if the conditions for "YES" are met
    if (v1 > v2 && (x2 - x1) % (v1 - v2) == 0) {
        cout << "YES";
    }
    // If none of the conditions are met, print "NO"
    else {
        cout << "NO";
    }
    
    return 0;
    

    }

    0|
    Permalink
  • DinaTAKLIT
    4 days ago+ 0 comments

    Javascript

    function kangaroo(x1, v1, x2, v2) {
        const division = (x2-x1) / (v1-v2)
        const reminder = (x2-x1) % (v1-v2)
        return division > 0 && reminder ==0 ? "YES" : "NO"
    }
    
    0|
    Permalink
  • bskavitha21
    5 days ago+ 0 comments
    if((x2>x1 )& (v2>=v1))
            return "NO";
        else if (((x2-x1)%(v1-v2)==0)&&((x2-x1)/(v1-v2)>0))
            return "YES";
        else 
            return "NO";
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy