Given a string **S**, the task is to find the count of maximum repeated frequency of characters in the given string S.

**Examples**:

Input:S = “geeksgeeks”

Output:Frequency 2 is repeated 3 times

Explanation:

Frequency of characters in the given string –

{“g”: 2, “e”: 4, “k”: 2, “s”: 2}

The frequency 2 is repeated thrice for the characters “g”, “k”, “s”.

Input:S = “abcabcdedee”

Output:Frequency 2 is repeated 4 times.

Explanation:

Frequency of characters in the given string –

{“a”: 2, “b”: 2, “c”: 2, “d”: 2, “e”: 3}

The frequency 2 is repeated four times for the characters “a”, “b”, “c”, “d”.

**Efficient Approach:**

- The idea is to first store the frequency of characters of the string in an array of size 26. Since all characters of strings are among 26 lowercase English alphabets, we can store the frequency of characters in an array of size 26.
- Create a hash map, to store the count of frequencies of the characters and return the frequency which occurred max times.

Below is the implementation of the above approach:

## C++

`// C++ implementation to find the ` `// maximum repeated frequency of ` `// characters in the given string ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find the maximum ` `// repeated frequency of the ` `// characters in the given string ` `void` `findMaxFrequency(string s) ` `{ ` ` ` `// Hash-Array to store the ` ` ` `// frequency of characters ` ` ` `int` `arr[26] = { 0 }; ` ` ` ` ` `// Loop to find the frequency ` ` ` `// of the characters ` ` ` `for` `(` `int` `i = 0; i < s.length(); i++) ` ` ` `arr[s[i] - ` `'a'` `]++; ` ` ` ` ` `// Hash map to store the occurrence ` ` ` `// of frequencies of characters ` ` ` `unordered_map<` `int` `, ` `int` `> hash; ` ` ` `for` `(` `int` `i = 0; i < 26; i++) ` ` ` `if` `(arr[i] != 0) ` ` ` `hash[arr[i]]++; ` ` ` ` ` `// Loop to find the maximum ` ` ` `// Repeated frequency from hash-map ` ` ` `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"` `; ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `string s = ` `"geeksgeeks"` `; ` ` ` ` ` `// Function Call ` ` ` `findMaxFrequency(s); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation to find the ` `// maximum repeated frequency of ` `// characters in the given String ` `import` `java.util.*; ` ` ` `class` `GFG{ ` ` ` `// Function to find the maximum ` `// repeated frequency of the ` `// characters in the given String ` `static` `void` `findMaxFrequency(String s) ` `{ ` ` ` `// Hash-Array to store the ` ` ` `// frequency of characters ` ` ` `int` `arr[] = ` `new` `int` `[` `26` `]; ` ` ` ` ` `// Loop to find the frequency ` ` ` `// of the characters ` ` ` `for` `(` `int` `i = ` `0` `; i < s.length(); i++) ` ` ` `arr[s.charAt(i) - ` `'a'` `]++; ` ` ` ` ` `// Hash map to store the occurrence ` ` ` `// of frequencies of characters ` ` ` `HashMap<Integer,Integer> hash = ` `new` `HashMap<Integer,Integer>(); ` ` ` `for` `(` `int` `i = ` `0` `; i < ` `26` `; i++) ` ` ` `if` `(arr[i] != ` `0` `) { ` ` ` `if` `(hash.containsKey(arr[i])){ ` ` ` `hash.put(arr[i], hash.get(arr[i])+` `1` `); ` ` ` `} ` ` ` `else` `{ ` ` ` `hash.put(arr[i], ` `1` `); ` ` ` `} ` ` ` `} ` ` ` ` ` `// Loop to find the maximum ` ` ` `// Repeated frequency from hash-map ` ` ` `int` `max_count = ` `0` `, res = -` `1` `; ` ` ` `for` `(Map.Entry<Integer,Integer> i : hash.entrySet()){ ` ` ` `if` `(max_count < i.getValue()) { ` ` ` `res = i.getKey(); ` ` ` `max_count = i.getValue(); ` ` ` `} ` ` ` `} ` ` ` ` ` `System.out.println(` `"Frequency "` `+ res+ ` `" is repeated "` ` ` `+ max_count+` `" times"` `); ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `String s = ` `"geeksgeeks"` `; ` ` ` ` ` `// Function Call ` ` ` `findMaxFrequency(s); ` `} ` `} ` ` ` `// This code is contributed by sapnasingh4991 ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 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 ` `def` `findMaxFrequency(s): ` ` ` ` ` `# Hash-Array to store the ` ` ` `# frequency of characters ` ` ` ` ` `arr ` `=` `[` `0` `]` `*` `26` ` ` ` ` `# Loop to find the frequency ` ` ` `# of the characters ` ` ` `for` `i ` `in` `range` `(` `len` `(s)): ` ` ` `arr[` `ord` `(s[i]) ` `-` `ord` `(` `'a'` `)] ` `+` `=` `1` ` ` ` ` `# Hash map to store the occurrence ` ` ` `# of frequencies of characters ` ` ` ` ` `hash` `=` `{} ` ` ` `for` `i ` `in` `range` `(` `26` `): ` ` ` `if` `(arr[i] !` `=` `0` `): ` ` ` `if` `arr[i] ` `not` `in` `hash` `: ` ` ` `hash` `[arr[i]] ` `=` `0` ` ` `hash` `[arr[i]] ` `+` `=` `1` ` ` ` ` `# Loop to find the maximum ` ` ` `# Repeated frequency from hash-map ` ` ` `max_count ` `=` `0` ` ` `res ` `=` `-` `1` ` ` `for` `i ` `in` `hash` `: ` ` ` `if` `(max_count < ` `hash` `[i]): ` ` ` `res ` `=` `i ` ` ` `max_count ` `=` `hash` `[i] ` ` ` ` ` `print` `(` `"Frequency"` `, res, ` `"is repeated"` `, max_count, ` `"times"` `) ` ` ` `# Driver Code ` ` ` `s ` `=` `"geeksgeeks"` ` ` `# Function Call ` `findMaxFrequency(s) ` ` ` `# This code is contributed by shubhamsingh10 ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation to find the ` `// maximum repeated frequency of ` `// characters in the given String ` `using` `System; ` `using` `System.Collections.Generic; ` ` ` `class` `GFG{ ` ` ` `// Function to find the maximum ` `// repeated frequency of the ` `// characters in the given String ` `static` `void` `findMaxFrequency(String s) ` `{ ` ` ` `// Hash-Array to store the ` ` ` `// frequency of characters ` ` ` `int` `[]arr = ` `new` `int` `[26]; ` ` ` ` ` `// Loop to find the frequency ` ` ` `// of the characters ` ` ` `for` `(` `int` `i = 0; i < s.Length; i++) ` ` ` `arr[s[i] - ` `'a'` `]++; ` ` ` ` ` `// Hash map to store the occurrence ` ` ` `// of frequencies of characters ` ` ` `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); ` ` ` `} ` ` ` `} ` ` ` ` ` `// Loop to find the maximum ` ` ` `// Repeated frequency from hash-map ` ` ` `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"` `); ` `} ` ` ` `// Driver Code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` `String s = ` `"geeksgeeks"` `; ` ` ` ` ` `// Function Call ` ` ` `findMaxFrequency(s); ` `} ` `} ` ` ` ` ` `// This code is contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

**Output:**

Frequency 2 is repeated 3 times

**Performance Analysis:**

**Time Complexity:**O(N)**Auxiliary Space:**O(N)

## Recommended Posts:

- Maximum length prefix such that frequency of each character is atmost number of characters with minimum frequency
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Maximum difference between frequency of two elements such that element having greater frequency is also greater
- Minimum characters to be replaced to make frequency of all characters same
- Queries for characters in a repeated string
- Character whose frequency is equal to the sum of frequencies of other characters of the given string
- Generate a number such that the frequency of each digit is digit times the frequency in given number
- Check if given string is a substring of string formed by repeated concatenation of z to a
- Permutation of a string with maximum number of characters greater than its adjacent characters
- Check if a string has all characters with same frequency with one variation allowed
- Remove even frequency characters from the string
- String with frequency of characters in Lucas Sequence
- Check whether frequency of characters in a string makes Fibonacci Sequence
- Number of Positions to partition the string such that atleast m characters with same frequency are present in each substring
- Remove odd frequency characters from the string
- Sort a string according to the frequency of characters
- Count of Binary Strings of length N such that frequency of 1's exceeds frequency of 0's
- Frequency of maximum occurring subsequence in given string
- Substring of length K having maximum frequency in the given string
- Check if a string can be repeated to make another string

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.