Lexicographical Smallest String

nurshuvo51 Stamford Individual Pract...
Limits 1s, 512 MB

There is a string $s$ of length $n$ containing lowercase letters and an integer $k$. Among the letters those appear exactly $k$ times in string $s$, pick the lexicographically maximum one. Now delete any (k-1) occurrences of this letter from the string in a way so that the resultant string is lexicographically smallest.

Note that if there is no letter which appears k times in s, no deletion takes place.

In this problem, you will have to determine what is the lexicographical smallest string after the deletions (possibly none)?


The first line of the input contains $n$ ($1 ≤ n ≤ 100000$), the number of lowercase letters in string $s$ and $k$ ($0 ≤ k ≤ 10$).

The second line contains the string $s$.


Print the lexicographically smallest string after the deletions (possibly none).


5 2


Login to submit.


61% Solution Ratio
tmwilliamlin168Earliest, Jan '20
AlfehsaniFastest, 0.0s
user.801384Lightest, 5.5 kB
bokaifShortest, 179B
Toph uses cookies. By continuing you agree to our Cookie Policy.