This tutorial provides Java solution to "Jumping on the Clouds" challenge of HackerRank.

# Hackerrank Challenge Details

**Problem Statement:**

Emma is playing a new mobile game involving n clouds numbered from 0 to n - 1. A player initially starts out on cloud c_{0}, and they must jump to cloud c_{n-1}. In each step, she can jump from any cloud to cloud or cloud .

There are two types of clouds, *ordinary clouds* and *thunderclouds*. The game ends if Emma jumps onto a thundercloud, but if she reaches the last cloud (i.e., c_{n-1}), she wins the game!

Can you find the minimum number of jumps Emma must make to win the game? It is guaranteed that clouds c_{0} and c_{n-1} are ordinary-clouds and it is *always possible* to win the game.

**Input Format:**

The first line contains an integer, n (the total number of clouds).

The second line contains n space-separated binary integers describing clouds c_{0}, c_{1}, c_{2},..., c_{n-1}.

- If c
_{i}= 0, the i^{th}cloud is an ordinary cloud. - If c
_{i}= 1, the i_{th}cloud is a thundercloud.

**Output Format:**

Print the minimum number of jumps needed to win the game.

**Constraints:**

- 2
__<__n__<__100 - ci € {0, 1}
- c
_{0}= c_{n-1}= 0

**Sample Input 0:**

```
7
0 0 1 0 0 1 0
```

**Sample Output 0:**

`4`

**Sample Input 1:**

```
6
0 0 0 0 1 0
```

**Sample Output 1:**

`3`

**Explanation:**

*Sample Case 0:*

Because c_{2} and c_{5} in our input are both 1, Emma must avoid c_{2} and c_{5}. Bearing this in mind, she can win the game with a minimum of 4 jumps:

*Sample Case 1:*

The only thundercloud to avoid is c_{4}. Emma can win the game in 3 jumps:

# Solution Details

**Java Implementation:**

```
package com.saintech.allprogtutorials.hackerrank.algos;
import java.util.Scanner;
/**
* @author Sain Technology Solutions
*
* Solution to Problem - https://www.hackerrank.com/challenges/jumping-on-the-clouds
*
*/
public class JumpingOnClouds {
public static void main(String[] args) {
final Scanner in = new Scanner(System.in);
final int N = in.nextInt();
// Put all the clouds in an array
final int[] clouds = new int[N];
for(int i = 0; i < N; i++) {
clouds[i] = in.nextInt();
}
// Check if two steps can be taken by verifying cloud type at
// second step. Otherwise check if one step can be taken by verifying
// if we still have any more clouds. If none of these conditions are met,
// break out of infinite loop.
int noOfJumps = 0, i = 0;
while(true) {
if(i + 2 < N && clouds[i + 2] == 0) {
i += 2;
} else if(i + 1 < N) {
i++;
} else {
break;
}
noOfJumps++;
}
System.out.println(noOfJumps);
in.close();
}
}
```

Thank you for reading through the tutorial. In case of any feedback/questions/concerns, you can communicate same to us through your comments and we shall get back to you as soon as possible.