dp [ i ] [ 1 ] = minimum flips required to make all previous states 0 or make previous states 1 satisfying the condition
dp [ i , 1 ] = Math . Min ( dp [ i - 1 , 0 ] , dp [ i - 1 , 1 ] ) + ( a [ i ] == '0' ? 1 : 0 ) ; } int answer = int . MaxValue ; for ( int i = 0 ; i < n ; i ++ ) { answer = Math . Min ( answer , dp [ i , 1 ] + dp [ n - 1 , 0 ] - dp [ i , 0 ] ) ; }