Given a string str consisting of lowercase English alphabets. The task is to find whether there is any character in the string whose frequency is equal to the sum of the frequencies of other characters of the string. If such character exists then print Yes else print No.
Input: str = “hkklkwwwww”
frequency(w) = frequency(h) + frequency(k) + frequency(l)
4 = 1 + 2 + 1
4 = 4
Input: str = “geeksforgeeks”
Approach: If the length of the string is odd then the result will always be No. In case of even length string, calculate the frequency of each of the character of the string and for any character if it’s frequency = half of the length of the string then the result will be Yes else No.
Below is the implementation of the above approach:
Time Complexity: O(len) where len is the length of the given string.
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.
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Find element in array with frequency equal to sum of frequencies of other elements
- Remove characters from given string whose frequencies are a Prime Number
- Maximum length prefix such that frequency of each character is atmost number of characters with minimum frequency
- Sum and Product of Prime Frequencies of Characters in a String
- Queries to count frequencies of a given character in a given range of indices
- Binary string with given frequencies of sums of consecutive pairs of characters
- Generate a Number in Decreasing order of Frequencies of characters of a given String
- Shortest distance to every other character from given character
- Longest sub-string having frequency of each character less than equal to k
- XOR of Prime Frequencies of Characters in a String
- Check whether the frequencies of all the characters in a string are prime or not
- Minimize Cost to sort a String in Increasing Order of Frequencies of Characters
- Replace every character of string by character whose ASCII value is K times more than it
- Minimum characters required to be removed to make frequency of each character unique
- Minimum addition/removal of characters to be done to make frequency of each character prime
- Sum of elements in an array with frequencies greater than or equal to that element
- Minimum characters to be replaced to make frequency of all characters same
- Length of the largest substring which have character with frequency greater than or equal to half of the substring
- Check if frequency of each character is equal to its position in English Alphabet
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.