Given a string of lowercase letters str of length N, the task is to reduce it by removing the characters which appear exactly K times in the string.
Input: str = “geeksforgeeks”, K = 2
Input: str = “geeksforgeeks”, K = 4
- Create a hash table of size 26, where 0th index represents ‘a’ and 1st index represent ‘b’ and so on.
- Initialize the hash table to zero.
- Iterate through the string and increment the frequency of each character(s[i]) in the hash table
- Now, once again traverse through the string and append the characters, with frequency K, in the new string.
Below is the implementation of the above approach:
Time Complexity: O(N)
- Remove characters from string that appears strictly less than K times
- Check if max occurring character of one string appears same no. of times in other
- Remove characters that appear more than k times
- Count of times second string can be formed from the characters of first string
- Largest sub-string where all the characters appear at least K times
- Find the only element that appears b times
- Remove characters from the first string which are present in the second string
- Remove even frequency characters from the string
- Remove odd frequency characters from the string
- Remove all characters other than alphabets from string
- Longest subsequence where every character appears at-least k times
- Remove all non-alphabetical characters of a String in Java
- How to remove all non-alphanumeric characters from a string in Java
- Count all elements in the array which appears at least K times after their first occurrence
- Number of ways to remove a sub-string from S such that all remaining characters are same
- Remove minimum characters from string to split it into three substrings under given constraints
- Maximum number of times str1 appears as a non-overlapping substring in str2
- Remove elements from the array which appear more than k times
- Remove elements that appear strictly less than k times
- Largest substring where all characters appear at least K times | Set 2