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
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Jumping on the Clouds
  5. Discussions

Jumping on the Clouds

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 3041 Discussions, By:

recency

Please Login in order to post a comment

  • jadhavsandesh402
    5 hours ago+ 0 comments
        int minJump = 0;
        int currIndex = 0;
        int itr = 0;
    
        while (currIndex < c.size() & itr < c.size()) {
    
            while (currIndex < c.size()-2 && c.get(currIndex+2) == 0) {
                currIndex = currIndex + 2;
                minJump++;
                // System.out.println(currIndex);
            } 
            while (currIndex < c.size()-1 && c.get(currIndex+1) == 0) {
                currIndex = currIndex + 1;
                minJump++;
                // System.out.println(currIndex);
            } 
            itr++;
        }
    
        // System.out.println(minJump);
    
    return minJump;
    
    0|
    Permalink
  • snjbadwaik
    3 days ago+ 0 comments

    public static int jumpingOnClouds(List c) { // Write your code here int count=0,i=0;

        while(i<c.size()){
            if(i+2<c.size()&&c.get(i+2)!=1){
                count++;
                System.out.println(i+" "+count);
                i=i+2;
            }        
            else{
                count++;
                System.out.println(i+" "+count);
    
                i=i+1;
            }           
        }
         return count-1;
    
    }
    
    0|
    Permalink
  • momodouwilliams
    1 week ago+ 0 comments

    My python3 solution

    def jumpingOnClouds(c):
        # Write your code here
        count = 0
        i = 0
    
        while i < len(c)-1:
                  
            if  (i + 2 < len(c)) and c[i+2] == 0:
                count += 1
                i += 2
            else:
                count += 1
                i += 1
        
        return count 
    
    0|
    Permalink
  • dumetrulo
    2 weeks ago+ 0 comments

    Clojure solution:

    (defn jumpingOnClouds [c]
      (let [cc (dec (count c))]
        (loop [i 0 j 0]
          (cond (>= i cc) j
                (= i (dec cc)) (inc j)
                true (recur (+ i (if (pos? (nth c (+ i 2))) 1 2))
                            (inc j))))))
    
    0|
    Permalink
  • verdox162
    2 weeks ago+ 0 comments
    def jumpingOnClouds(c):
        # Write your code here
        count_jumps = 0
        i=0
        while i < len(c)-1:
            count_jumps+=1
            i+= 2 if i+2<len(c) and not c[i+2] else 1
        return count_jumps
    
    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