Minimize flips required such that string does not any pair of consecutive 0 s | C # program for the above approach ; Function to find minimum flips required such that a String does not contain any pair of consecutive 0 s ; Stores minimum count of flips ; Iterate over the characters of the String ; If two consecutive characters are equal to '0' ; Update S [ i + 1 ] ; Update cntOp ; Driver Code
using System ; class GFG { static int cntMinOperation ( char [ ] S , int N ) { int cntOp = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( S [ i ] == '0' && S [ i + 1 ] == '0' ) { S [ i + 1 ] = '1' ; cntOp += 1 ; } } return cntOp ; } public static void Main ( string [ ] args ) { string S = "10001" ; int N = S . Length ; Console . WriteLine ( cntMinOperation ( S . ToCharArray ( ) , N ) ) ; } }