Given a string str containing only lowercase characters. The task is to print the characters having an even frequency in the order of their occurrence.
Note: Repeated elements with even frequency are printed as many times they occur in order of their occurrences.
Input: str = “geeksforgeeks”
Character Frequency ‘g’ 2 ‘e’ 4 ‘k’ 2 ‘s’ 2 ‘f’ 1 ‘o’ 1 ‘r’ 1
‘g’, ‘e’, ‘k’ and ‘s’ are the only characters with even frequencies.
Input: str = “aeroplane”
Approach: Create a frequency array to store the frequency of each of the character of the given string str. Traverse the string str again and check whether the frequency of that character is even. If yes, then print the character.
Below is the implementation of the above approach:
Time Complexity: O(n)
Auxiliary Space: O(1)
- Print characters having odd frequencies in order of occurrence
- Print characters and their frequencies in order of occurrence
- Print characters having prime frequencies in order of occurrence
- Print characters and their frequencies in order of occurrence using a LinkedHashMap in Java
- Print characters and their frequencies in order of occurrence using Binary Tree
- Print 2-D co-ordinate points in ascending order followed by their frequencies
- Print the last occurrence of elements in array in relative order
- Print characters in decreasing order of frequency
- Print common characters of two Strings in alphabetical order
- Print all distinct characters of a string in order (3 Methods)
- Python code to print common characters of two Strings in alphabetical order
- Queries for frequencies of characters in substrings
- XOR of Prime Frequencies of Characters in a String
- Sum and Product of Prime Frequencies of Characters in a String
- Check whether the frequencies of all the characters in a string are prime or not