A ground station recorded a raw transcript of decoded symbols during a satellite downlink session, stored as a string of lowercase letters. Atmospheric interference occasionally produces a symbol that shows up only a handful of times purely by chance; the station's engineers only trust a symbol as genuine signal if it occurs at least k times somewhere in the entire transcript. Clean up the transcript by deleting every occurrence of any symbol that occurs fewer than k times overall, keeping all remaining symbols in their original relative order.
Line 1: the transcript string s, consisting only of lowercase English letters. Line 2: a single integer k.
Print the cleaned transcript: s with every occurrence of any character whose total frequency in s is less than k removed, preserving the original relative order of the remaining characters. If every character is removed, print an empty line.
Example 1
Input
abacabad 3
Expected
aaaa
Explanation
In `abacabad`, `a` occurs 4 times, `b` occurs 2 times, `c` occurs 1 time, and `d` occurs 1 time. Only `a` meets the threshold k=3, so every `b`, `c`, and `d` is deleted, leaving the four `a`s in their original order: `aaaa`.
Example 2
Input
mississippi 2
Expected
ississippi
Explanation
In `mississippi`, `m` occurs 1 time, `i` occurs 4 times, `s` occurs 4 times, and `p` occurs 2 times. Every character except `m` meets the threshold k=2, so the single `m` is deleted and the rest stay in order, giving `ississippi`.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →