Skip to content

Commit ba35259

Browse files
committed
[Hacker Rank]: Jumping on the Clouds doc moved as Markdown
1 parent 71f6523 commit ba35259

File tree

2 files changed

+121
-112
lines changed

2 files changed

+121
-112
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# [Jumping on the Clouds](https://www.hackerrank.com/challenges/jumping-on-the-clouds)
2+
3+
Difficulty: #easy
4+
Category: #implementation
5+
6+
There is a new mobile game that starts with consecutively numbered clouds.
7+
Some of the clouds are thunderheads and others are cumulus. The player can
8+
jump on any cumulus cloud having a number that is equal to the number of the
9+
current cloud plus $ 1 $ or $ 2 $. The player must avoid the thunderheads. Determine
10+
the minimum number of jumps it will take to jump from the starting postion
11+
to the last cloud. It is always possible to win the game.
12+
13+
For each game, you will get an array of clouds numbered $ 0 $ if they are safe
14+
or $ 1 $ if they must be avoided.
15+
16+
## Example
17+
18+
$ c = [0, 1, 0, 0, 0, 1, 0] $
19+
20+
Index the array from 0...6. The number on each cloud is its index in the
21+
list so the player must avoid the clouds at indices 1 and 5. They could
22+
follow these two paths: `0 -> 2 -> 4 -> 6 or 0 -> 2 -> 3 -> 4 -> 6.`
23+
The first path takes $ 3 $ jumps while the second takes $ 4 $. Return $ 3 $.
24+
25+
## Function Description
26+
27+
Complete the jumpingOnClouds function in the editor below.
28+
29+
jumpingOnClouds has the following parameter(s):
30+
31+
* int c[n]: an array of binary integers
32+
33+
## Returns
34+
35+
* int: the minimum number of jumps required
36+
37+
## Input Format
38+
39+
The first line contains an integer n, the total number of clouds.
40+
The second line contains n space-separated binary integers describing
41+
clouds c[i] where 0 <= i < n.
42+
43+
## Constraints
44+
45+
$ 2 <= n < 100 $ \
46+
$ c[i] ∈ {0, 1} $ \
47+
$ c[0] = c[m -1] = 0 $
48+
49+
## Output format
50+
51+
Print the minimum number of jumps needed to win the game.
52+
53+
## Sample Input 0
54+
55+
```text
56+
7
57+
0 0 1 0 0 1 0
58+
```
59+
60+
## Sample Output 0
61+
62+
```text
63+
4
64+
```
65+
66+
## Explanation 0
67+
68+
The player must avoid $ c[2] $ and $ c[5] $. The game can be won with a minimum
69+
of 4 jumps:
70+
71+
```mermaid
72+
flowchart BT
73+
0 -.- 1 -.- 2 -.- 3 -.- 4 -.- 5 -.- 6
74+
0 --> 1 --> 3 --> 4 --> 6
75+
76+
0(0):::cumulus
77+
1(1):::cumulus
78+
2(2):::storm
79+
3(3):::cumulus
80+
4(4):::cumulus
81+
5(5):::storm
82+
6(6):::cumulus
83+
84+
linkStyle default stroke:blue
85+
classDef cumulus fill:#90FE96,color:#000;
86+
classDef storm fill:#FE5C5E,color:#000;
87+
```
88+
89+
## Sample Input 1
90+
91+
```text
92+
6
93+
0 0 0 0 1 0
94+
```
95+
96+
## Sample Output 1
97+
98+
```text
99+
3
100+
```
101+
102+
## Explanation 1
103+
104+
The only thundercloud to avoid is c[4]. The game can be won in 3 jumps:
105+
106+
```mermaid
107+
flowchart BT
108+
0 -.- 1 -.- 2 -.- 3 -.- 4 -.- 5
109+
0 --> 2 --> 3 --> 5
110+
111+
0(0):::cumulus
112+
1(1):::cumulus
113+
2(2):::cumulus
114+
3(3):::cumulus
115+
4(4):::storm
116+
5(5):::cumulus
117+
118+
linkStyle default stroke:blue
119+
classDef cumulus fill:#90FE96,color:#000;
120+
classDef storm fill:#FE5C5E,color:#000;
121+
```

src/hackerrank/implementation/jumpingOnClouds.ts

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,3 @@
1-
/**
2-
* Jumping on the Clouds
3-
*
4-
* https://www.hackerrank.com/challenges/jumping-on-the-clouds
5-
*
6-
* There is a new mobile game that starts with consecutively numbered clouds.
7-
* Some of the clouds are thunderheads and others are cumulus. The player can
8-
* jump on any cumulus cloud having a number that is equal to the number of the
9-
* current cloud plus 1 or 2. The player must avoid the thunderheads. Determine
10-
* the minimum number of jumps it will take to jump from the starting postion
11-
* to the last cloud. It is always possible to win the game.
12-
*
13-
* For each game, you will get an array of clouds numbered 0 if they are safe
14-
* or 1 if they must be avoided.
15-
*
16-
* # Example
17-
* c = [0, 1, 0, 0, 0, 1, 0]
18-
*
19-
* Index the array from 0...6. The number on each cloud is its index in the
20-
* list so the player must avoid the clouds at indices 1 and 5. They could
21-
* follow these two paths: 0 -> 2 -> 4 -> 6 or 0 -> 2 -> 3 -> 4 -> 6.
22-
* The first path takes 3 jumps while the second takes 4. Return 3.
23-
*
24-
* # Function Description
25-
*
26-
* Complete the jumpingOnClouds function in the editor below.
27-
*
28-
* jumpingOnClouds has the following parameter(s):
29-
*
30-
* * int c[n]: an array of binary integers
31-
*
32-
* # Returns
33-
* * int: the minimum number of jumps required
34-
*
35-
* # Input Format
36-
* The first line contains an integer n, the total number of clouds.
37-
* The second line contains n space-separated binary integers describing
38-
* clouds c[i] where 0 <= i < n.
39-
*
40-
* # Constraints
41-
* 2 <= n < 100
42-
* c[i] ∈ {0, 1}
43-
* c[0] = c[m -1] = 0
44-
*
45-
* # Output format
46-
* Print the minimum number of jumps needed to win the game.
47-
*
48-
* # Sample Input 0
49-
* ```
50-
* 7
51-
* 0 0 1 0 0 1 0
52-
*
53-
* # Sample Output 0
54-
* ```
55-
* 4
56-
* ```
57-
*
58-
* # Explanation 0:
59-
*
60-
* The player must avoid c[2] and c[5]. The game can be won with a minimum
61-
* of 4 jumps:
62-
*
63-
* ```mermaid
64-
* flowchart BT
65-
* 0 -.- 1 -.- 2 -.- 3 -.- 4 -.- 5 -.- 6
66-
* 0 --> 1 --> 3 --> 4 --> 6
67-
*
68-
* 0(0):::cumulus
69-
* 1(1):::cumulus
70-
* 2(2):::storm
71-
* 3(3):::cumulus
72-
* 4(4):::cumulus
73-
* 5(5):::storm
74-
* 6(6):::cumulus
75-
*
76-
* linkStyle default stroke:blue
77-
* classDef cumulus fill:#90FE96
78-
* classDef storm fill:#FE5C5E
79-
* ```
80-
*
81-
* # Sample Input 1
82-
* ```
83-
* 6
84-
* 0 0 0 0 1 0
85-
* ```
86-
*
87-
* # Sample Output 1
88-
* ```
89-
* 3
90-
* ```
91-
*
92-
* # Explanation 1:
93-
* The only thundercloud to avoid is c[4]. The game can be won in 3 jumps:
94-
*
95-
* ```mermaid
96-
* flowchart BT
97-
* 0 -.- 1 -.- 2 -.- 3 -.- 4 -.- 5
98-
* 0 --> 2 --> 3 --> 5
99-
*
100-
* 0(0):::cumulus
101-
* 1(1):::cumulus
102-
* 2(2):::cumulus
103-
* 3(3):::cumulus
104-
* 4(4):::storm
105-
* 5(5):::cumulus
106-
*
107-
* linkStyle default stroke:blue
108-
* classDef cumulus fill:#90FE96
109-
* classDef storm fill:#FE5C5E
110-
* ```
111-
*/
112-
1131
import { logger as console } from '../../logger';
1142

1153
export function jumpingOnClouds(c: number[]): number {

0 commit comments

Comments
 (0)