Count the elements having frequency equals to its value | C # program to count the elements having frequency equals to its value ; Function to find the count ; Hash map for counting frequency ; Counting freq of each element ; Check if value equals to frequency and increment the count ; Driver code ; Function call
using System ; using System . Collections . Generic ; class GFG { static int find_maxm ( int [ ] arr , int n ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . ContainsKey ( arr [ i ] ) ) { mp [ arr [ i ] ] = mp [ arr [ i ] ] + 1 ; } else { mp . Add ( arr [ i ] , 1 ) ; } } int ans = 0 ; foreach ( KeyValuePair < int , int > x in mp ) { int value = x . Key ; int freq = x . Value ; if ( value == freq ) { ans ++ ; } } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 2 , 2 , 3 , 4 , 3 } ; int n = arr . Length ; Console . Write ( find_maxm ( arr , n ) ) ; } }