dp [ i ] [ 1 ] = minimum flips required to make all previous states 0 or make previous states 1 satisfying the condition
dp [ i ] [ 1 ] = min ( dp [ i - 1 ] ) + int ( a [ i ] == '0' ) NEW_LINE answer = 10 ** 18 NEW_LINE for i in range ( n ) : NEW_LINE answer = min ( answer , dp [ i ] [ 1 ] + dp [ n - 1 ] [ 0 ] - dp [ i ] [ 0 ] ) NEW_LINE