Minimize removal of non | Function to find minimum count of steps required ot make string S an empty string ; Stores count of occurences ' ( ' ; Stores count of occurences ' ) ' ; Traverse the string , str ; If current character is ' ( ' ; Update count_1 ; Update count_2 ; If all the characters are same , then print - 1 ; If the count of occurence of ' ) ' and ' ( ' are same then print 0 ; If length of string is Odd ; Given string ; Size of the string ; Function Call
function canReduceString ( S , N ) { var count_1 = 0 ; var count_2 = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( S [ i ] === " " ) { count_1 ++ ; } else { count_2 ++ ; } } if ( count_1 === 0 count_2 === 0 ) { document . write ( " " + " " ) ; } else if ( count_1 === count_2 ) { document . write ( " " + " " ) ; } else if ( N % 2 !== 0 ) { document . write ( " " ) ; } else { document . write ( Math . abs ( count_1 - count_2 ) / 2 ) ; } } var S = " " ; var N = S . length ; canReduceString ( S , N ) ;