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
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool cntMinOperation ( string 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 ; } int main ( ) { string S = "10001" ; int N = S . length ( ) ; cout << cntMinOperation ( S , N ) ; return 0 ; }