Minimum number of flips to make a Binary String increasing | C # program for the above approach ; ; Function to find the minimum number of flips required to make String increasing ; Length of s ; Total number of zero in s ; Stores count of 1 s till ith index ; stors the minimum count of flip ; Traverse the given String ; Update the value of res and count of 1 s ; Return the minimum number of flips ; Utility count ; Driver code ; Given String ; function call
using System ; public class GFG { static int minimumFlips ( String s ) { int n = s . Length ; int cnt0 = count ( s , '0' ) ; int cnt1 = 0 ; int res = n - cnt0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == '0' ) { cnt0 -= 1 ; } else if ( s [ i ] == '1' ) { res = Math . Min ( res , cnt1 + cnt0 ) ; cnt1 ++ ; } } return res ; } private static int count ( String s , char c ) { int ans = 0 ; for ( int j = 0 ; j < s . Length ; j ++ ) { char i = s [ j ] ; if ( c == i ) ans ++ ; } return ans ; } static public void Main ( ) { String S = "000110" ; Console . Write ( minimumFlips ( S ) ) ; } }