Given a string of lowercase English alphabets. The task is to check if the count of distinct characters in the string is prime or not.
Input : str = "geeksforgeeks" Output :Yes Explanation: The number of distinct characters in the string is 7, and 7 is a prime number. Input : str ="geeks" Output : No
In this problem first we have to count the distinct characters in the string. We will use a map to store the frequency of each alphabets. The next step is to count the number of distinct characters, and check whether the number is prime or not .
If the number is prime we will print Yes, else No.
Below is the implementation of the above approach:
- Check whether the frequencies of all the characters in a string are prime or not
- Count characters in a string whose ASCII values are prime
- String with k distinct characters and no same characters adjacent
- Count number of substrings with exactly k distinct characters
- Count distinct substrings that contain some characters at most k times
- Convert given string so that it holds only distinct characters
- Print all distinct characters of a string in order (3 Methods)
- Sort an array according to the increasing count of distinct Prime Factors
- Length of the smallest sub-string consisting of maximum distinct characters
- Count of distinct sums that can be obtained by adding prime numbers from given arrays
- XOR of Prime Frequencies of Characters in a String
- Sum and Product of Prime Frequencies of Characters in a String
- Program to print characters present at prime indexes in a given string
- Replace minimal number of characters to make all characters pair wise distinct
- Count of distinct substrings of a string using Suffix Array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.