In this video, we will write a C++ program to return the maximum occurring character in an input string.
For Example:
Input String = GeeksforGeeks
Output= e
Here we use the “Hashing” method to return the maximum occurring character in an input string.
Algorithm:
Step 1: First we traverse through the string, we would hash each character into an array of ASCII characters.
Step 2: Now we construct a character count array from the input string, and store the occurrence value.
Step 3: Print the index of the maximum value in the count array.
Example:
Input = Hellooo
Output = o
Dry Run:
count['H'] = 1
count['e] = 1
count['l'] = 2
count[‘o’]= 3
ASCII characters are 256, so we use our Hash array size as 256. But if we know that our input string will have characters with the value from 0 to 127 only, we can limit the Hash array size to 128. Similarly, based on extra info known about input string, the Hash array size can be limited to 26
Related Article : https://www.geeksforgeeks.org/return-maximum-occurring-character-in-the-input-string/