Count removal of pairs required to be empty all Balanced Parenthesis subsequences | Function to find the maximum count of pairs required to be removed such that subsequence of string does not contain any valid parenthesis ; Stores count of pairs of balanced parenthesis ; Stores count of curly balanced parenthesis ; Stores count of small balanced parenthesis ; Stores count of square balanced parenthesis ; Iterate over characters of the string ; Update cntCurly ; Update cntSml ; Update cntSqr ; Update cntCurly ; Update cntPairs ; Update cntSml ; Update cntPairs ; Update cntSml ; Update cntPairs ; Given String ; Function call
function cntBalancedParenthesis ( s , N ) { var cntPairs = 0 ; var cntCurly = 0 ; var cntSml = 0 ; var cntSqr = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == ' ' ) { cntCurly ++ ; } else if ( s . charAt ( i ) == ' ' ) { cntSml ++ ; } else if ( s . charAt ( i ) == ' ' ) { cntSqr ++ ; } else if ( s . charAt ( i ) == ' ' && cntCurly > 0 ) { cntCurly -- ; cntPairs ++ ; } else if ( s . charAt ( i ) == ' ' && cntSml > 0 ) { cntSml -- ; cntPairs ++ ; } else if ( s . charAt ( i ) == ' ' && cntSqr > 0 ) { cntSqr -- ; cntPairs ++ ; } } document . write ( cntPairs ) ; } var s = " " ; var N = s . length ; cntBalancedParenthesis ( s , N ) ;