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
def check ( s ) : NEW_LINE INDENT fr = [ 0 ] * 26 NEW_LINE n = len ( s ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT x = ord ( s [ i ] ) NEW_LINE fr [ x - 97 ] += 1 NEW_LINE DEDENT minimum = 99999999999 NEW_LINE for i in range ( 26 ) : NEW_LINE INDENT for j in range ( i + 1 , 26 ) : NEW_LINE INDENT z = fr [ i ] + fr [ j ] NEW_LINE minimum = min ( minimum , n - z ) NEW_LINE DEDENT DEDENT return minimum NEW_LINE DEDENT s = " geeksforgeeks " NEW_LINE print ( check ( s ) ) NEW_LINE