Created
April 26, 2022 07:33
-
-
Save rachidelaid/533b2c3262bcee47789573ee1be944ba to your computer and use it in GitHub Desktop.
this is a challenge from hackerrank https://www.hackerrank.com/challenges/jumping-on-the-clouds-revisited/problem?isFullScreen=true
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function jumpingOnClouds(c, k) { | |
let index = 0; | |
let energy = 100; | |
let stop = false; | |
while (!stop) { | |
if (c[index] === 1) { | |
energy -= 2; | |
} | |
energy -= 1; | |
index = (index + k) % c.length; | |
if (index === 0) { | |
stop = true; | |
} | |
} | |
return energy; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment