Minimum delete operations to make all elements of array same | Function to get minimum number of elements to be deleted from array to make array elements equal ; Create an dictionary and store frequencies of all array elements in it using element as key and frequency as value ; Find maximum frequency among all frequencies . ; To minimize delete operations , we remove all elements but the most frequent element . ; Driver code
def minDelete ( arr , n ) : NEW_LINE INDENT freq = { } NEW_LINE for i in range ( n ) : NEW_LINE INDENT if arr [ i ] in freq : NEW_LINE INDENT freq [ arr [ i ] ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT freq [ arr [ i ] ] = 1 ; NEW_LINE DEDENT DEDENT max_freq = 0 ; NEW_LINE for i , j in freq . items ( ) : NEW_LINE INDENT max_freq = max ( max_freq , j ) ; NEW_LINE DEDENT return n - max_freq ; NEW_LINE DEDENT arr = [ 4 , 3 , 4 , 4 , 2 , 4 ] ; NEW_LINE n = len ( arr ) NEW_LINE print ( minDelete ( arr , n ) ) ; NEW_LINE