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 occurrence. 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:
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.
- Minimize ASCII values sum after removing all occurrences of one character
- Length of longest Fibonacci subarray formed by removing only one element
- Minimize length of Substrings containing at least one common Character
- Convert the string into palindrome string by changing only one character.
- Lexicographically smallest string formed by removing at most one character
- Group multiple occurrence of array elements ordered by first occurrence
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Minimum length of Run Length Encoding possible by removing at most K characters from a given string
- Minimize cost to empty a given string by removing characters alphabetically
- Map every character of one string to another such that all occurrences are mapped to the same character
- Program to count occurrence of a given character in a string
- Generate two output strings depending upon occurrence of character in input string.
- Generate two output strings depending upon occurrence of character in input string in Python
- Count occurrence of a given character in a string using Stream API in Java
- Python | Replacing Nth occurrence of multiple characters in a String with the given character
- Find the Nth occurrence of a character in the given String
- Remove the first and last occurrence of a given Character from a String
- Find indices of all occurrence of one string in other
- Palindrome by swapping only one character
- Character replacement after removing duplicates from a string
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.