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:
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.
- Count of ungrouped characters after dividing a string into K groups of distinct characters
- Count of Distinct strings possible by inserting K characters in the original string
- Check whether the frequencies of all the characters in a string are prime or not
- String Range Queries to count number of distinct characters with updates
- Count ways to partition a string such that both parts have equal distinct characters
- Count characters in a string whose ASCII values are prime
- Find distinct characters in distinct substrings of a string
- String with k distinct characters and no same characters adjacent
- Count of substrings having all distinct characters
- Count number of substrings with exactly k distinct characters
- Count distinct substrings that contain some characters at most k times
- Count of substrings of length K with exactly K distinct characters
- Count of distinct power of prime factor of N
- Count of distinct characters in a substring by given range for Q queries
- Find the String having each substring with exactly K distinct characters
- Convert given string so that it holds only distinct characters
- Count the number of strings in an array whose distinct characters are less than equal to M
- Sort an array of strings based on count of distinct characters
- Print all distinct characters of a string in order (3 Methods)
- Contiguous subsegments of a string having distinct subsequent characters
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.