Update the frequencies of all the array elements
for ( int i = 0 ; i < n ; i ++ ) { if ( umap . ContainsKey ( arr [ i ] ) ) umap [ arr [ i ] ] ++ ; else umap [ arr [ i ] ] = 1 ; } Dictionary < int , int > . ValueCollection valueColl = umap . Values ; foreach ( int val in valueColl ) {