Minimize the length of string by removing occurrence of only one character | Function to find the minimum length ; Count the frequency of each alphabet ; Find the alphabets with maximum frequency ; Subtract the frequency of character from length of string ; Driver Code
def minimumLength ( s ) : NEW_LINE INDENT maxOcc = 0 NEW_LINE n = len ( s ) NEW_LINE arr = [ 0 ] * 26 NEW_LINE for i in range ( n ) : NEW_LINE INDENT arr [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1 NEW_LINE DEDENT for i in range ( 26 ) : NEW_LINE INDENT if arr [ i ] > maxOcc : NEW_LINE INDENT maxOcc = arr [ i ] NEW_LINE DEDENT DEDENT return n - maxOcc NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str = " afddewqd " NEW_LINE print ( minimumLength ( str ) ) NEW_LINE DEDENT