Mode of frequencies of given array elements | C # program of the above approach ; Function to find the mode of the frequency of the array ; Stores the frequencies of array elements ; Traverse through array elements and count frequencies ; Stores the frequencies 's of  frequencies of array elements ; Stores the minimum value ; Find the Mode in 2 nd map ; Search for this Mode ; When mode is find then return to main function . ; If mode is not found ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int countFreq ( int [ ] arr , int n ) { Dictionary < int , int > mp1 = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( mp1 . ContainsKey ( arr [ i ] ) ) { mp1 [ arr [ i ] ] = mp1 [ arr [ i ] ] + 1 ; } else { mp1 . Add ( arr [ i ] , 1 ) ; } } Dictionary < int , int > mp2 = new Dictionary < int , int > ( ) ; foreach ( KeyValuePair < int , int > it in mp1 ) { if ( mp2 . ContainsKey ( it . Value ) ) { mp2 [ it . Value ] = mp2 [ it . Value ] + 1 ; } else { mp2 . Add ( it . Value , 1 ) ; } } int M = int . MinValue ; foreach ( KeyValuePair < int , int > it in mp2 ) { M = Math . Max ( M , it . Value ) ; } foreach ( KeyValuePair < int , int > it in mp2 ) { if ( M == it . Value ) { return it . Key ; } } return 0 ; } public static void Main ( String [ ] args ) { int [ ] arr = { 6 , 10 , 3 , 10 , 8 , 3 , 6 , 4 } ; int n = arr . Length ; Console . Write ( countFreq ( arr , n ) ) ; } }