Jumping on the Clouds: Revisited

  • + 0 comments
    function jumpingOnClouds(c, k) {
        let n = c.length, energy = 100; 
        let index = 0; 
        
        do {
            energy -= c[index] === 1 ? 3 : 1;
            index = (index + k ) % n; 
        }while(index !== 0);
        
        return energy;  
    }