Given a string str of lowercase alphabets, the task is to check if the frequency of each distinct characters in the string equals to its position in the English Alphabet. If valid, then print “Yes”, else print “No”.
Input: str = “abbcccdddd”
Since frequency of each distinct character is equals to its position in English Alphabet, i.e.
F(a) = 1,
F(b) = 2,
F(c) = 3, and
F(d) = 4
Hence the output is Yes.
Input: str = “geeksforgeeks”
- Store the frquency of each character in an array of 26, for hashing purpose.
- Now traverse the hash array and check if frequency of each characters at an index i is equal to (i + 1) or not.
- If yes, then print “Yes”, Else print “No”.
Below is the implementation of the above approach:
Time Complexity: O(N), where N is the length of the string.
Auxiliary Space: O(26)
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 characters at same position as in English alphabet
- Check input character is alphabet, digit or special character
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- For each lowercase English alphabet find the count of strings having these alphabets
- Longest sub-string having frequency of each character less than equal to k
- Character whose frequency is equal to the sum of frequencies of other characters of the given string
- Check if the frequency of any character is more than half the length of the string
- Length of the largest substring which have character with frequency greater than or equal to half of the substring
- Find letter's position in Alphabet using Bit operation
- Maximum length prefix such that frequency of each character is atmost number of characters with minimum frequency
- Count of character pairs at same distance as in English alphabets
- Check if two strings can be made equal by swapping one character among each other
- Check if two strings after processing backspace character are equal or not
- Smallest alphabet greater than a given character
- Frequency of each character in a String using unordered_map in C++
- Print the frequency of each character in Alphabetical order
- Printing frequency of each character just after its consecutive occurrences
- Index of character depending on frequency count in string
- Largest index for each distinct character in given string with frequency K
- Print number of words, vowels and frequency of each character
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.
Improved By : sapnasingh4991