Minimize flips required such that string does not any pair of consecutive 0 s | 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
function cntMinOperation ( S , N ) { let cntOp = 0 ; for ( let i = 0 ; i < N - 1 ; i ++ ) { if ( S [ i ] == ' ' && S [ i + 1 ] == ' ' ) { S [ i + 1 ] = ' ' ; cntOp += 1 ; } } return cntOp ; } let S = " " ; let N = S . length ; document . write ( cntMinOperation ( S . split ( ' ' ) , N ) ) ;