text: Minimum flips to remove any consecutive 3 0 s or 1 s in given Binary string | C # program for the above approach ; Function to find the minimum number of flips to make all three pairs of consecutive characters different ; Stores resultant count of pairs ; Base Case ; Iterate over the range [ 0 , N - 2 ] ; If the consecutive 3 numbers are the same then increment the count and the counter ; Return the answer ; Driver Code
code: using System ; public class GFG { static int minFlips ( string str ) { int count = 0 ; if ( str . Length <= 2 ) { return 0 ; } for ( int i = 0 ; i < str . Length - 2 ; ) { if ( str [ i ] == str [ i + 1 ] && str [ i + 2 ] == str [ i + 1 ] ) { i = i + 3 ; count ++ ; } else { i ++ ; } } return count ; } public static void Main ( string [ ] args ) { string S = "0011101" ; Console . WriteLine ( minFlips ( S ) ) ; } }