Maximum number of 0 s that can be flipped such that Array has no adjacent 1 s | Maximum number of 0 s that can be replaced by 1 ; Check for three consecutive 0 s ; Flip the bit ; Increase the count ; Driver code
def canReplace ( arr , n ) : NEW_LINE INDENT i = 0 NEW_LINE count = 0 NEW_LINE while ( i < n ) : NEW_LINE INDENT if ( arr [ i ] == 0 and ( i == 0 or arr [ i - 1 ] == 0 ) and ( i == n - 1 or arr [ i + 1 ] == 0 ) ) : NEW_LINE INDENT arr [ i ] = 1 NEW_LINE count += 1 NEW_LINE DEDENT i += 1 NEW_LINE DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 0 , 0 , 0 , 1 ] NEW_LINE print ( canReplace ( arr , 5 ) ) NEW_LINE DEDENT