
String Transformation Problem Statement
Given a string str
of length N, perform a series of operations to create a new string:
- Select the smallest character from the first 'K' characters of the string, remove it from the string and append it to the new string.
- Continue this process until the original string is empty.
If fewer than 'K' characters remain, sort these characters and append them in order to the new string.
Input:
The first line contains an integer 'T' denoting the number of test cases.
For each test case, the input contains a single string and an integer 'K' separated by a space.
Output:
For each test case, output the new string formed after performing the operations. Each output should be on a new line.
Example:
Input:
2
edcba 4
abcde 2
Output:
bacde
abcde
Constraints:
1 <= T <= 100
0 < N <= 10^5
1 <= K <= 10^5
- Time Limit: 1 second
Note:
The string contains only lowercase letters and no spaces. Do not print from your function; use return values instead.

AnswerBot
6d

The problem involves selecting the smallest character from the first 'K' characters of a string and appending it to a new string until the original string is empty.
Iterate through the string, selectin...read more

Help your peers!
Add answer anonymously...
Top Amazon Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Amazon Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app