Sort by

recency

|

3290 Discussions

|

  • + 0 comments

    python3 Solution

    def jumpingOnClouds(c):
        pos = 0
        res = -1
        while pos < len(c):
            if pos + 2 < len(c) and c[pos+2] != 1:
                res += 1
                pos += 2
            else:
                res += 1
                pos += 1
            
        return res
    
  • + 0 comments

    This max score is not fair compared with some other challenges way more intricate than this one...

    Java 8 solution:

    class Result {
    
        public static int jumpingOnClouds(List<Integer> c) {
            int i=0, jumps=0;
            while (i<c.size()) {
                i = i + ((i < c.size()-2 && c.get(i+2)==0) ? 2 : 1);
                jumps++;
            }
            return jumps-1;
        }
    
    }
    
  • + 0 comments

    Here is jumping on the CLOUD problem solution in python, java, c++, c and javascript - https://programmingoneonone.com/hackerrank-jumping-on-the-clouds-problem-solution.html

  • + 0 comments

    Guys, this is a math problem. The solution lies in understanding that it's just walks and jumps. The solution can be defined as: floor((n+walks)/2), where n is the total number of clouds. A walk in this case represents a forced walk (when there is an even number of clouds between two consecutive thunderclouds)

    My solution in python:

    def jumpingOnClouds(c):
        # Write your code here
        n = len(c)
        walks = 0
        last_thunderhead = -1
        for i in range(n):
            if c[i]:
                if (i - last_thunderhead)%2:
                    walks += 1
                last_thunderhead = i
        return math.floor((n + walks)/2)
    
  • + 0 comments

    C++

    int jumpingOnClouds(vector<int> &c) {
        int cnt = 0;
    
        for (int j = 0; j < c.size() - 1; j = j + 2) {
            if (c[j + 2] == 1) {
                j--;
                cnt++;
            } else { cnt++; }
        }
    
        return cnt;
    }