Traverse the array and update frequencies in hash
for ( int i = 0 ; i < N ; i ++ ) { if ( hash . ContainsKey ( arr [ i ] ) ) { hash . Add ( arr [ i ] , hash [ arr [ i ] ] + 1 ) ; } else { hash . Add ( arr [ i ] , 1 ) ; } } for ( int i = 0 ; i < N ; i ++ ) {