Given a string str, the task is to print the frequency of each of the characters of str in alphabetical order.
Input: str = “aabccccddd”
Since it is already in alphabetical order, the frequency
of the characters is returned for each character.
Input: str = “geeksforgeeks”
- Create a Map to store the frequency of each of the characters of the given string.
- Iterate through the string and check if the character is present in the map.
- If the character is not present, insert it in the map with 1 as the initial value else increment its frequency by 1.
- Finally, print the frequency of each of the character in alphabetical order.
Below is the implementation of the above approach:
Time Complexity: O(n)
Auxiliary Space: O(1)
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Print common characters of two Strings in alphabetical order
- Python code to print common characters of two Strings in alphabetical order
- Print characters in decreasing order of frequency
- Print number of words, vowels and frequency of each character
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Maximum length prefix such that frequency of each character is atmost number of characters with minimum frequency
- Reorder the position of the words in alphabetical order
- Check whether the vowels in a string are in alphabetical order or not
- Check if the characters of a given string are in alphabetical order
- Find alphabetical order such that words can be considered sorted
- Frequency of each character in a String using unordered_map in C++
- Printing frequency of each character just after its consecutive occurrences
- Longest sub-string having frequency of each character less than equal to k
- Largest index for each distinct character in given string with frequency K
- Character whose frequency is equal to the sum of frequencies of other characters of the given 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 email@example.com. 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.
Improved By : AnkitRai01