Finding the frequency of each element .
j = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] not in freq ) : NEW_LINE INDENT dist [ j ] = arr [ i ] NEW_LINE j += 1 NEW_LINE freq [ arr [ i ] ] = 0 NEW_LINE DEDENT if ( arr [ i ] in freq ) : NEW_LINE INDENT freq [ arr [ i ] ] += 1 NEW_LINE DEDENT DEDENT dist = dist [ : j ] NEW_LINE