Jumping on the Clouds: Revisited

  • + 0 comments
    int jumpingOnClouds(vector<int> c, int k) {
        int e = 100;
        int cloud = 0;
        
        while (e>0) {
            cloud += k;  
            e--;
            
            if(cloud>=c.size()){
                cloud-=c.size();
            }
            
            if(c[cloud]==1){
                e-=2;
            }
            
            if(cloud==0){
                return e;
            }
        }
        
        return e;
    }