Minimum changes required to make all element in an array equal | Function to count of minimum changes required to make all elements equal ; Store the count of each element as key - value pair in Dictionary ; Traverse through the Dictionary and find the maximum occurring element ; Return count of all element minus count of maximum occurring element ; Driver code ; Function call
def minChanges ( arr , n ) : NEW_LINE INDENT mp = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if arr [ i ] in mp . keys ( ) : NEW_LINE INDENT mp [ arr [ i ] ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT mp [ arr [ i ] ] = 1 NEW_LINE DEDENT DEDENT maxElem = 0 NEW_LINE for x in mp : NEW_LINE INDENT maxElem = max ( maxElem , mp [ x ] ) NEW_LINE DEDENT return n - maxElem NEW_LINE DEDENT arr = [ 2 , 3 , 3 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( minChanges ( arr , n ) ) NEW_LINE