Given a string str containing only lowercase alphabets, the task is to minimize the length of the string after performing the following operation:
- Delete all occurrences of any one character from this string.
Input: str = "abccderccwq" Output: 7 character 'c' will be deleted since it has maximum occurence. Input: str = "dddded" Output: 1 character 'd' will be deleted
- Maintain the frequency of each and every character in an array.
- Find the character with the maximum frequency.
- Finally, subtract the length of the original string with the frequency of that character to get the desired answer.
Below is the implementation of the above approach:
- Minimize ASCII values sum after removing all occurrences of one character
- Program to count occurrence of a given character in a string
- Count occurrence of a given character in a string using Stream API in Java
- Generate two output strings depending upon occurrence of character in input string.
- Character replacement after removing duplicates from a string
- Generate two output strings depending upon occurrence of character in input string in Python
- Lexicographically smallest string formed by removing at most one character
- Minimum sum of squares of character counts in a given string after removing k characters
- Check if the frequency of any character is more than half the length of the string
- Rearrange given string to maximize the occurrence of string t
- Replace every character of string by character whose ASCII value is K times more than it
- Find a string such that every character is lexicographically greater than its immediate next character
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Find indices of all occurrence of one string in other
- Group multiple occurrence of array elements ordered by first occurrence
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.