Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Lexicographical Smallest String

By nurshuvo51 · Limits 1s, 512 MB

There is a string ss of length nn containing lowercase letters and an integer kk. Among the letters those appear exactly kk times in string ss, 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 nn (1n1000001 ≤ n ≤ 100000), the number of lowercase letters in string ss and kk (0k100 ≤ k ≤ 10).

The second line contains the string ss.


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


5 2


Toph uses cookies. By continuing you agree to our Cookie Policy.