Loop to count the maximum number of 0 s that will be replaced by 1 s
for ( int j = 0 ; j < s . length ( ) ; j ++ ) { if ( ar [ j ] == 0 ) { ans ++ ; for ( int g = j ; g <= j + k && g < s . length ( ) ; g ++ ) { ar [ g ] = -1 ; end = g ; } j = end - 1 ; } } return ans ; }