Skip to content
Programmingoneonone
Programmingoneonone
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

HackerRank Jumping on the Clouds problem solution

YASH PAL, 31 July 202430 November 2025

In this HackerRank Jumping on the clouds interview preparation kit problem For each game, you will get an array of clouds numbered 0 if they are safe or 1 if they must be avoided.

HackerRank Jumping on the Clouds Interview preparation kit solution

HackerRank Jumping on the Clouds problem solution in Python programming.

#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the jumpingOnClouds function below.
def jumpingOnClouds(c):
    x,y = 0,0
    while x<len(c)-2:
        x = x+1 if c[x+2] else x+2
        y+=1
    if x<len(c)-1:
        y+=1
    return y


if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    n = int(input())

    c = list(map(int, input().rstrip().split()))

    result = jumpingOnClouds(c)

    fptr.write(str(result) + 'n')

    fptr.close()

Jumping on the Clouds Problem solution in Java Programming.

import java.io.*;
import java.util.*;

public class Solution {
  private static InputReader in;
  private static PrintWriter out;

  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out, true);

    int n = in.nextInt();
    int[] arr = new int[n];
    for (int i = 0; i < n; i++) {
      arr[i] = in.nextInt();
    }
    int[] dp = new int[n];
    for (int i = 1; i < n; i++) {
      if (arr[i] == 1) dp[i] = 1 << 29;
      dp[i] = 1 << 29;
      if (i >= 1 && arr[i-1] == 0) dp[i] = Math.min(dp[i], dp[i-1]+1);
      if (i >= 2 && arr[i-2] == 0) dp[i] = Math.min(dp[i], dp[i-2]+1);
    }
    out.println(dp[n-1]);
    
    out.close();
    System.exit(0);
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }
  }


}

Problem solution in C++ programming.

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;


int main(){
    int n;
    cin >> n;
    vector<int> c(n, INT_MAX/2);
    for(int i = 0;i < n;i++){
       int x;
        cin >> x;
        if (x == 1) continue;
        if (i == 0) c[i] = 0;
        else if (i == 1) c[i] = 1 + c[0];
        else c[i] = min(c[i-1], c[i-2]) + 1;
    }
    cout << c.back() << endl;
    return 0;
}

Problem solution in C programming.

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
    int n; 
    scanf("%d",&n);
    int *c = malloc(sizeof(int) * n);
    for(int c_i = 0; c_i < n; c_i++){
       scanf("%d",&c[c_i]);
    }
    int i, count=0;
    for(i=0;i<n;i++){
        if(i+1==n-1 || i+2==n-1){
            count++;
            printf("%dn",count);
            break;
        }
        else if(c[i+2]==0){
           i++;
           count++;
        }
        else if(c[i+1]==0){
           count++;
        }
    }
    return 0;
}

Problem solution in JavaScript programming.

process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
    input_stdin += data;
});

process.stdin.on('end', function () {
    input_stdin_array = input_stdin.split("n");
    main();    
});

function readLine() {
    return input_stdin_array[input_currentline++];
}

/////////////// ignore above this line ////////////////////

function main() {
    var n = parseInt(readLine());
    c = readLine().split(' ');
    c = c.map(Number);
    
    var i = 0;
    var jump = 0;
    
    while (i < n) {
        if (c[i+2] === 0) {
            jump++;
            i += 2;
        }
        else if (c[i+1] === 0) {
            jump++;
            i++;
        }
        else {
            // Thunder Cloud...
            i++;
        }
        
    }
    
    console.log(jump);

}

coding problems solutions interview prepration kit AlgorithmsHackerRankinterview preparation

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for just 7 dollars. Ask all your career-related questions to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes