We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Jumping on the Clouds: Revisited
Jumping on the Clouds: Revisited
+ 0 comments java
public class Solution { public static void main(String []args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int step=0; int e=100; int k= scan.nextInt(); int []a = new int[n+1]; for(int i=0;i<n;i++) { a[i]= scan.nextInt(); } while(true) { step +=k; step%=n; e--; if(a[step]==1) e-=2; if(step==0) break; } System.out.print(e); } }
+ 0 comments My JavaScript Solution
function jumpingOnClouds(c, k) { let i = 0; let energy = 100; do { if (c[i] == 1) energy -= 2; i = (i + k) % c.length; energy--; } while (i !== 0); return energy; }
+ 0 comments What if its all energy is drained?
+ 0 comments static int jumpingOnClouds(int[] c, int k) { int i=0; int n = c.length; int energy = 100; do { if (c[i] == 1) { energy -= 2; } i = (i + k) % n; energy--; } while (i != 0); return energy; }
+ 0 comments in node js****
function jumpingOnClouds(c, k) { let energy = 100 const n = c.length let i = 0
do { if (c[i] === 1) { energy -= 2 } i = (i + k) % n energy-- } while (i !== 0) return energy
}
Load more conversations
Sort 1088 Discussions, By:
Please Login in order to post a comment