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

    You are viewing a single comment's thread. Return to all comments →

  • adarsh_2425
    4 months ago+ 0 comments

    Solution in C

    char* kangaroo(int x1, int v1, int x2, int v2) {
        
        char *s = malloc (10 * sizeof(char));
        int relativeSpeed;
        
        //if speed of kangaroo 1 is slower or equal to kangaroo 2,    they will never meet
        if (v1 <= v2) {
            s = "NO";
        }
        else {
            //finding relative speed
            relativeSpeed = x2 - x1;
            
            //If relativeSpeed % (v1 - v2) == 0, then the kangaroos will meet at some future time.
            if (relativeSpeed % (v1 - v2) == 0) {
                s = "YES";
            }
            else {
                s = "NO";
            }
        }
        
        return s;
        free(s);
    }
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy