Maximum repeated frequency of characters in a given string | C # implementation to find the maximum repeated frequency of characters in the given String ; Function to find the maximum repeated frequency of the characters in the given String ; Hash - Array to store the frequency of characters ; Loop to find the frequency of the characters ; Hash map to store the occurrence of frequencies of characters ; Loop to find the maximum Repeated frequency from hash - map ; Driver Code ; Function Call
using System ; using System . Collections . Generic ; class GFG { static void findMaxFrequency ( String s ) { int [ ] arr = new int [ 26 ] ; for ( int i = 0 ; i < s . Length ; i ++ ) arr [ s [ i ] - ' a ' ] ++ ; Dictionary < int , int > hash = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < 26 ; i ++ ) if ( arr [ i ] != 0 ) { if ( hash . ContainsKey ( arr [ i ] ) ) { hash [ arr [ i ] ] = hash [ arr [ i ] ] + 1 ; } else { hash . Add ( arr [ i ] , 1 ) ; } } int max_count = 0 , res = - 1 ; foreach ( KeyValuePair < int , int > i in hash ) { if ( max_count < i . Value ) { res = i . Key ; max_count = i . Value ; } } Console . WriteLine ( " Frequency ▁ " + res + " ▁ is ▁ repeated ▁ " + max_count + " ▁ times " ) ; } public static void Main ( String [ ] args ) { String s = " geeksgeeks " ; findMaxFrequency ( s ) ; } }