Computing frequencies of all elements
int freq [ MAX ] ; memset ( freq , 0 , sizeof ( freq ) ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < 1 && arr [ i ] > MAX ) { cout << " Out ▁ of ▁ range " ; return -1 ; } freq [ arr [ i ] ] += 1 ; }