Find array elements with frequencies in range [ l , r ] | C ++ program to find the elements whose frequency lies in the range [ l , r ] ; Hash map which will store the frequency of the elements of the array . ; Increment the frequency of the element by 1. ; Print the element whose frequency lies in the range [ l , r ] ; Driver code
#include " iostream " NEW_LINE #include " unordered _ map " NEW_LINE using namespace std ; void findElements ( int arr [ ] , int n , int l , int r ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < n ; ++ i ) { mp [ arr [ i ] ] ++ ; } for ( int i = 0 ; i < n ; ++ i ) { if ( l <= mp [ arr [ i ] ] && mp [ arr [ i ] <= r ] ) { cout << arr [ i ] << " ▁ " ; } } } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 3 , 2 , 2 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int l = 2 , r = 3 ; findElements ( arr , n , l , r ) ; return 0 ; }