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:
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.
- 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
- 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
- Generate a Number in Decreasing order of Frequencies of characters of a given String
- Binary string with given frequencies of sums of consecutive pairs of characters
- Minimize Cost to sort a String in Increasing Order of Frequencies of Characters
- 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 even frequencies in order of occurrence
- Print characters and their frequencies in order of occurrence
- Print characters having odd frequencies in order of occurrence
- Array elements with prime frequencies
- Numbers with prime frequencies greater than or equal to k
- Print characters and their frequencies in order of occurrence using Binary Tree
- Print characters and their frequencies in order of occurrence using a LinkedHashMap in Java
- Rearrange the characters of the string such that no two adjacent characters are consecutive English alphabets
- Count of ungrouped characters after dividing a string into K groups of distinct characters