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)
- 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
- Check if the characters of a given string are in alphabetical order
- Check whether the vowels in a string are in alphabetical order or not
- Reorder the position of the words in alphabetical order
- Find alphabetical order such that words can be considered sorted
- Longest sub-string having frequency of each character less than equal to k
- Printing frequency of each character just after its consecutive occurrences
- Index of character depending on frequency count in string
- Check if the frequency of any character is more than half the length of the string
- Character whose frequency is equal to the sum of frequencies of other characters of the given string
- Python | Check order of character in string using OrderedDict( )
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