AlgoUniversity
  • Go Back
Discussion
Lexicographical Jisho :

Author

Yash Sahijwani

Difficulty Level : Hard

Submissions : 246

Asked In : Uber

Marks :50

: 3 | : 1

There is a game called Jisho in Japan. In that, players are given an integer $$$alpha$$$ and a string $$$beta$$$ to play with. The players have to choose some positions (indexes) from the string such that at least 1 position from the chosen set is present in any continuous substring of length $$$alpha$$$.

The players then have to form the smallest lexicographic string with the help of the letters corresponding to those indices (they can rearrange the letters to form the smallest lexicographic string).

Adi wants to win the game, therefore, he comes to you for help. Help Adi by returning the smallest lexicographic string possible with these conditions.

You can learn more about lexicographic strings here.

Input

The first line of input consists of the string $$$beta$$$ $$$(1 \leq |beta| \leq 10^5)$$$. The string consists of only lowercase Latin letters. The second line of input consists of a single integer $$$alpha$$$ $$$(1 \leq alpha \leq |beta|)$$$.

Output

The output should consist of a single string $$$-$$$ the smallest possible lexicographic string.

Examples

Input
aacaa
4
Output
a
Input
abcab
2
Output
aab

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.