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
function find_maxm ( arr , n ) { let mpp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( mpp . has ( arr [ i ] ) ) { mpp . set ( arr [ i ] , mpp . get ( arr [ i ] ) + 1 ) } else { mpp . set ( arr [ i ] , 1 ) } } let ans = 0 ; for ( let x of mpp ) { let value = x [ 0 ] ; let freq = x [ 1 ] ; if ( value == freq ) { ans ++ ; } } return ans ; } let arr = [ 3 , 2 , 2 , 3 , 4 , 3 ] ; let n = arr . length ; document . write ( find_maxm ( arr , n ) ) ;