Minimize flips required such that string does not any pair of consecutive 0 s | Java 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
import java . util . * ; 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 ( ) ; System . out . print ( cntMinOperation ( S . toCharArray ( ) , N ) ) ; } }