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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findMaxFrequency ( string s ) { int arr [ 26 ] = { 0 } ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) arr [ s [ i ] - ' a ' ] ++ ; unordered_map < int , int > hash ; for ( int i = 0 ; i < 26 ; i ++ ) if ( arr [ i ] != 0 ) hash [ arr [ i ] ] ++ ; int max_count = 0 , res = -1 ; for ( auto i : hash ) { if ( max_count < i . second ) { res = i . first ; max_count = i . second ; } } cout << " Frequency ▁ " << res << " ▁ is ▁ repeated ▁ " << max_count << " ▁ times " ; } int main ( ) { string s = " geeksgeeks " ; findMaxFrequency ( s ) ; return 0 ; }