Minimize removal of alternating subsequences to empty given Binary String | Function to find the minimum number of operations required to empty the string ; Initialize variables ; Traverse the string ; If current character is 0 ; Update maximum consecutive 0 s and 1 s ; Print the minimum operation ; input string ; length of string ; Function Call
function minOpsToEmptyString ( S , N ) { let one = 0 , zero = 0 ; let x0 = 0 , x1 = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( S [ i ] == ' ' ) { x0 ++ ; x1 = 0 ; } else { x1 ++ ; x0 = 0 ; } zero = Math . max ( x0 , zero ) ; one = Math . max ( x1 , one ) ; } document . write ( Math . max ( one , zero ) ) ; } let S = " " ; let N = S . length ; minOpsToEmptyString ( S , N ) ;