Maximizing the elements with a [ i + 1 ] > a [ i ] | Returns the number of positions where A ( i + 1 ) is greater than A ( i ) after rearrangement of the array ; Creating a HashMap containing char as a key and occurrences as a value ; Find the maximum frequency ; Driver code
def countMaxPos ( arr ) : NEW_LINE INDENT n = len ( arr ) NEW_LINE Map = { } NEW_LINE for x in arr : NEW_LINE INDENT if x in Map : NEW_LINE INDENT Map [ x ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT Map [ x ] = 1 NEW_LINE DEDENT DEDENT max_freq = 0 NEW_LINE for entry in Map : NEW_LINE INDENT max_freq = max ( max_freq , Map [ entry ] ) NEW_LINE DEDENT return n - max_freq NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 20 , 30 , 10 , 50 , 40 ] NEW_LINE print ( countMaxPos ( arr ) ) NEW_LINE DEDENT