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
using System ; using System . Collections . Generic ; class GFG { static void findElements ( int [ ] arr , int n , int l , int r ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { int a = 0 ; if ( ! mp . ContainsKey ( arr [ i ] ) ) { a = 1 ; } else { a = mp [ arr [ i ] ] + 1 ; } if ( ! mp . ContainsKey ( arr [ i ] ) ) { mp . Add ( arr [ i ] , a ) ; } else { mp . Remove ( arr [ i ] ) ; mp . Add ( arr [ i ] , a ) ; } } for ( int i = 0 ; i < n ; ++ i ) { if ( mp . ContainsKey ( arr [ i ] ) && l <= mp [ arr [ i ] ] && ( mp [ arr [ i ] ] <= r ) ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 3 , 2 , 2 , 5 } ; int n = arr . Length ; int l = 2 , r = 3 ; findElements ( arr , n , l , r ) ; } }