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
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • 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 2900 Discussions, By:

votes

Please Login in order to post a comment

  • hassanmohsin
    3 years ago+ 49 comments

    My python solution

    def jumpingOnClouds(c):
        if len(c) == 1 : return 0
        if len(c) == 2: return 0 if c[1]==1 else 1
        if c[2]==1: 
            return 1 + jumpingOnClouds(c[1:])
        if c[2]==0:
            return 1 + jumpingOnClouds(c[2:])
    
    330|
    Permalink
    View more Comments..
  • tao_zhang
    6 years ago+ 80 comments

    My Java solution:

    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            int c[] = new int[n];
            for(int i=0; i < n; i++){
                c[i] = in.nextInt();
            }
            int count = -1;
            for (int i = 0; i < n; i++, count++) {
                if (i<n-2 && c[i+2]==0) i++;
            }
            System.out.println(count);
        }
    }
    
    275|
    Permalink
    View more Comments..
  • lucas_chapola
    5 years ago+ 40 comments

    java solution

    int count = 0;
    for (int i = 0; i < n - 1; i++) {
        if (c[i] == 0) i++;
        count++;
    }
    System.out.println(count);
    
    210|
    Permalink
    View more Comments..
  • creetar
    6 years ago+ 6 comments

    C#

            var jumps = 0;
            for(int i=0; i<n-1; i++, jumps++)
                if (i+2 < n && c[i+2] == 0)
                    i++;
            
            Console.WriteLine(jumps);
    
    46|
    Permalink
    View more Comments..
  • rajesh_nitian54
    6 years ago+ 13 comments

    two line code

        for(i=0;i<(n-1);) 
        arr[i+2]?(res++,i++):(res++,i+=2);        
        cout<<res;
    
    39|
    Permalink
    View more Comments..
Load more conversations

Need Help?


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