Iterate over every element in the array and increase the frequency of the element in hash map
for ( int i = 0 ; i < n ; ++ i ) { if ( freq . ContainsKey ( arr [ i ] ) ) { freq [ arr [ i ] ] ++ ; } else { freq . Add ( arr [ i ] , 1 ) ; } } int res = 0 ;