Alex and his String
Practice
3.8 (10 votes)
Algorithms
Easy
Implementation
Priority queue
String manipulation
Problem
79% Success 5264 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Alex has a string S of length N consisting of lowercase alphabets. He wants to find lexicographically smallest string X of length N that can be formed using the following operation.

In one operation, he can select any one character among the at most first K characters of string S, remove it from string S and append it to string X. He can apply this operation as many times as he wants.

Help Alex find the string X.

Input format

  • The first line consists of a string of length N
  • The second line consists of an integer K.

Output format

  • Print the lexicographically minimum string that can be formed using the above operation.

Constraints

  • \(1 \le N \le 10^{5}\)
  • \(1 \le K \le N\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
92 votes
Tags:
Ad-HocApprovedBrute-force searchData StructuresEasyOpen
Points:20
96 votes
Tags:
AlgorithmsBrute ForceEasyString Manipulationeasy
Points:20
642 votes
Tags:
Ad-HocEasyOpenString Manipulation