Given a string , the task is to check if the frequencies of all the characters of the string are prime or not. If all the frequencies are prime then print otherwise print .
Input: str = “geeksforgeeks”
Character Frequency g 2 e 4 k 2 s 2 f 1 o 1 r 1
It is clear that only the frequencies of g, k and s are prime.
Input: str = “aabbbccccc”
Approach: Find the frequencies of all the characters present in the string and store them in a map. Then check whether all the frequencies are prime or not, if all the frequency are prime then print else .
Below is the implementation of the above approach:
- XOR of Prime Frequencies of Characters in a String
- Sum and Product of Prime Frequencies of Characters in a String
- Print characters having prime frequencies in order of occurrence
- Check whether count of distinct characters in a string is Prime or not
- Character whose frequency is equal to the sum of frequencies of other characters of the given string
- Count characters in a string whose ASCII values are prime
- Program to print characters present at prime indexes in a given string
- Check whether second string can be formed from characters of first string
- Queries for frequencies of characters in substrings
- Print characters having even frequencies in order of occurrence
- Print characters having odd frequencies in order of occurrence
- Print characters and their frequencies in order of occurrence
- Check if both halves of the string have same set of characters
- Quick way to check if all the characters of a string are same
- Array elements with prime frequencies
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.