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
- Character replacement after removing duplicates from a string
- Generate two output strings depending upon occurrence of character in input string.
- Lexicographically smallest string formed by removing at most one character
- Generate two output strings depending upon occurrence of character in input string in Python
- 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
- Find a string such that every character is lexicographically greater than its immediate next character
- Replace every character of string by character whose ASCII value is K times more than it
- 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 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.