File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ // https://www.hackerrank.com/challenges/jumping-on-the-clouds-revisited/problem
2
+
3
+ package implimentation ;
4
+
5
+ import java .util .Scanner ;
6
+
7
+ public class JumpingOnTheCloudsRevisited {
8
+ private static final Scanner scanner = new Scanner (System .in );
9
+
10
+ public static void main (String [] args ) {
11
+ int length = scanner .nextInt ();
12
+ int jump = scanner .nextInt ();
13
+ int [] clouds = getArray (length );
14
+ System .out .println (finalEnergy (clouds , jump ));
15
+ }
16
+
17
+ private static int finalEnergy (int [] array , int jump ) {
18
+ int energy = 99 ;
19
+ for (int index = jump % array .length ; index != 0 ; index = (index + jump ) % array .length , energy --) {
20
+ energy -= 2 * array [index ];
21
+ }
22
+ return energy - 2 * array [0 ];
23
+ }
24
+
25
+ private static int [] getArray (int length ) {
26
+ int [] array = new int [length ];
27
+ for (int index = 0 ; index < array .length ; index ++){
28
+ array [index ] = scanner .nextInt ();
29
+ }
30
+ return array ;
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments