Given a string containing only lowercase english alphabets. The task is to find the bitwise XOR of all the prime frequencies of the characters in the string. If no prime frequency is present, then print -1.
Input : str = "gggggeeekkkks" Output : 6 Input : str = "aabbbbw" Output : -1
- Traverse the string and store the frequencies of all the characters using map STL.
- Find the frequencies which are prime numbers using Sieve Of Eratosthenes.
- Calculate XOR of all these prime frequencies.
Below is the implementation of the above approach:
- Check whether the frequencies of all the characters in a string are prime or not
- Sum and Product of Prime Frequencies of Characters in a String
- Character whose frequency is equal to the sum of frequencies of other characters of the given string
- Check whether count of distinct characters in a string is Prime or not
- Count characters in a string whose ASCII values are prime
- Program to print characters present at prime indexes in a given string
- Queries for frequencies of characters in substrings
- Print characters having odd frequencies in order of occurrence
- Print characters and their frequencies in order of occurrence
- Array elements with prime frequencies
- Numbers with prime frequencies greater than or equal to k
- Permutation of a string with maximum number of characters greater than its adjacent characters
- Min flips of continuous characters to make all characters same in a string
- String with k distinct characters and no same characters adjacent
- Convert all lowercase characters to uppercase whose ASCII value is co-prime with k
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.