Store the frequency of k
for i in range ( n ) : NEW_LINE INDENT if k [ arr [ i ] ] in freq . keys ( ) : NEW_LINE INDENT freq [ k [ arr [ i ] ] ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT freq [ k [ arr [ i ] ] ] = 1 NEW_LINE DEDENT DEDENT Sum = 0 NEW_LINE