Given a string str containing only lowercase English alphabets, the task is to find the sum and product of all the prime frequencies of the characters in str.
Input: str = “geeksforgeeks”
Output: 6, 8
Only characters ‘g’, ‘k’ and ‘s’ have prime frequencies i.e. 2 + 2 + 2 = 6 and 2 * 2* 2 = 8
Character frequency g 2 e 4 k 2 s 2 f 1 o 1 r 1
Input: str = “algorithms”
Output: 0, 0
- Traverse the string and store the frequencies of all the characters in a hash table.
- Find the frequencies which are prime using Sieve Of Eratosthenes.
- Calculate the sum and product of all of these prime frequencies and finally print the sum and product.
Below is the implementation of the above approach:
Sum = 6 Product = 8
- XOR of Prime Frequencies of Characters in a String
- Check whether the frequencies of all the characters in a string are prime or not
- Print characters having prime frequencies in order of occurrence
- Character whose frequency is equal to the sum of frequencies of other characters of the given string
- Binary string with given frequencies of sums of consecutive pairs of characters
- Python | Check if frequencies of all characters of a string are different
- Minimize Cost to sort a String in Increasing Order of Frequencies of Characters
- Generate a Number in Decreasing order of Frequencies of characters of a given String
- Print characters and their 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
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Queries for frequencies of characters in substrings
- Print characters having odd frequencies in order of occurrence
- Print characters having even frequencies in order of occurrence
- Numbers with prime frequencies greater than or equal to k
- Array elements with prime frequencies
- Sum and product of k smallest and k largest prime numbers in the array
- String with k distinct characters and no same characters adjacent
- Sum and Product of all Prime Nodes of a Singly Linked List
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.