Minimum flips required to form given binary string where every flip changes all bits to its right as well | C # program for the above approach ; Function to return the count of minimum flips required ; If curr occurs in the readonly string ; Switch curr to '0' if '1' or vice - versa ; Driver code
using System ; class GFG { public static int minFlips ( String target ) { char curr = '1' ; int count = 0 ; for ( int i = 0 ; i < target . Length ; i ++ ) { if ( target [ i ] == curr ) { count ++ ; curr = ( char ) ( 48 + ( curr + 1 ) % 2 ) ; } } return count ; } public static void Main ( String [ ] args ) { String S = "011000" ; Console . WriteLine ( minFlips ( S ) ) ; } }