Remove Abundant Characters
You are given a string s of lowercase English characters and an integer k. You have to remove all characters that occur k or more times in the string.
Return the final string.
Note: The final string can be empty.
Example 1:
Input:Â s = "aadbbcccca", k = 3
Output:Â "dbb"
Explanation:
Character frequencies in s:
- 'a'Â appears 3 times
- 'd'Â appears 1 time
- 'b'Â appears 2 times
- 'c'Â appears 4 times
'a' and 'c' appear k or more times. Hence 'a' and 'c' will be removed from the string.
Final string = "dbb".
Example 2:
Input:Â s = "xyz", k = 2
Output:Â "xyz"
Explanation:
All characters ('x', 'y', 'z') appear exactly once, which is fewer than 2. Thus the whole string is returned.
Now Your Turn!
Pick the correct output for the given inputInput: s="aabbcc", k=3
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= s.length <= 100
- s contains only lowercase English characters
- 1 <= k <= 100