Check if frequency of each element in given array is unique or not | C # code for the above approach ; Function to check whether the frequency of elements in array is unique or not . ; Freq map will store the frequency of each element of the array ; Store the frequency of each element from the array ; Check whether frequency of any two or more elements are same or not . If yes , return false ; Return true if each frequency is unique ; Driver Code ; Given array [ ] arr ; Function call ; Print the result
using System ; using System . Collections . Generic ; class GFG { static bool checkUniqueFrequency ( int [ ] arr , int n ) { Dictionary < int , int > freq = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq . ContainsKey ( arr [ i ] ) ) { freq [ arr [ i ] ] = freq [ arr [ i ] ] + 1 ; } else { freq . Add ( arr [ i ] , 1 ) ; } } HashSet < int > uniqueFreq = new HashSet < int > ( ) ; foreach ( KeyValuePair < int , int > i in freq ) { if ( uniqueFreq . Contains ( i . Value ) ) return false ; else uniqueFreq . Add ( i . Value ) ; } return true ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 1 , 2 , 5 , 5 } ; int n = arr . Length ; bool res = checkUniqueFrequency ( arr , n ) ; if ( res ) Console . Write ( " Yes " + " STRNEWLINE " ) ; else Console . Write ( " No " + " STRNEWLINE " ) ; } }