Minimum deletions from string to reduce it to string with at most 2 unique characters | Function to find the minimum deletions ; Array to store the occurrences of each characters ; Length of the string ; ASCII of the character ; Increasing the frequency for this character ; Choosing two character ; Finding the minimum deletion ; Driver code
function check ( s ) { var i , j ; var fr = Array ( 26 ) . fill ( 0 ) ; var n = s . length ; for ( i = 0 ; i < n ; i ++ ) { var x = s [ i ] ; fr [ x . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] += 1 ; } var minimum = 10000000000 ; for ( i = 0 ; i < 26 ; i ++ ) { for ( j = i + 1 ; j < 26 ; j ++ ) { var z = fr [ i ] + fr [ j ] ; minimum = Math . min ( minimum , n - z ) ; } } return minimum ; } var s = " " ; document . write ( check ( s ) ) ;