![]() |
VOOZH | about |
Given string s, we need is to find the maximum occurring character in the string str.
Examples:
Input: s="geeksforgeeks"
Output: 'e'
Explanation: 'e' occurs 4 times in the stringInput: s="test"
Output: 't'
Explanation: 't' occurs 2 times in the string
In this approach we simply use the unordered_map from STL to store the frequency of every character and while adding characters to map we take a variable count to determine the element having highest frequency.
Implementation :
Max occurring character is: s
The idea is to store the frequency of every character in the array and return the character with maximum count.
Follow the steps to solve the problem:
Below is the implementation of the above approach:
Character: e, Count: 4
Time Complexity: O(N), Traversing the string of length N one time.
Auxiliary Space: O(1)