Jumping on the Clouds: Revisited

  • + 0 comments

    Java 8 Code

    // Complete the jumpingOnClouds function below.

    static int jumpingOnClouds(int[] c, int k) {
        int index =0;
        int e =100;
        for(int i =0;i<c.length;i++){
            index = (index+k)%c.length;
            if(c[index]==1){
                e = e-3;
            }else{
                e = e-1;
            }
            if(index==0){
                break;
            }
        }
    
      return e;
    }