Loop to count the maximum number of 0 s that will be replaced by 1 s
for j in range ( len ( s ) ) : NEW_LINE INDENT if ( ar [ j ] == 0 ) : NEW_LINE INDENT ans += 1 NEW_LINE for g in range ( j , len ( s ) ) : NEW_LINE INDENT if ( g <= j + k ) : NEW_LINE INDENT ar [ g ] = - 1 NEW_LINE end = g NEW_LINE DEDENT DEDENT j = end - 1 NEW_LINE DEDENT DEDENT return ans NEW_LINE