AlgoUniversity
  • Go Back
Discussion
Lexicographically Largest Kth Occurence :

Author

Ujjwal Srivastava

Difficulty Level : Medium

Submissions : 542

Asked In : PhonePe

Marks :30

: 10 | : 0

Bob gave Alex a string $$$s$$$ consisting of lowercase English letters of length $$$n.$$$ He then asked Alex to construct a new string $$$s1$$$ using the characters of $$$s$$$ such that no two characters appear more than $$$k$$$ times consecutively. It is not mandatory to use all characters from $$$s.$$$

Help Alex find the lexicographically largest possible string $$$s1.$$$

Input

The first line contains two space-separated integers $$$n$$$ and $$$k$$$. The second line contains a string $$$s$$$ of length $$$n$$$.$$$(1 \le n \le 10^5).$$$$$$( 1\le k \le n.)$$$

Output

Output the lexicographically largest string.

Examples

Input
7 3
xxxxzza
Output
zzxxxax
Input
19 3
zzzzzzxxxzzaabbazza
Output
zzzxzzzxzzzxzbbaaa
Input
9 2
cledqiwly
Output
ywqlliedc

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.