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)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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
- Print common characters of two Strings in alphabetical order
- Python code to print common characters of two Strings in alphabetical order
- Find alphabetical order such that words can be considered sorted
- Check if the characters of a given string are in alphabetical order
- Reorder the position of the words in alphabetical order
- Check whether the vowels in a string are in alphabetical order or not
- Print number of words, vowels and frequency of each character
- Generate a number such that the frequency of each digit is digit times the frequency in given number
- Longest sub-string having frequency of each character less than equal to k
- Printing frequency of each character just after its consecutive occurrences
- Largest index for each distinct character in given string with frequency K
- Check if frequency of each character is equal to its position in English Alphabet
- Frequency of each character in a String using unordered_map in C++
- Minimum characters required to be removed to make frequency of each character unique
- Minimum addition/removal of characters to be done to make frequency of each character prime
- Print characters in decreasing order of frequency
- Sum of the alphabetical values of the characters of a string
- Remove all non-alphabetical characters of a String in Java
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.