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
4mo
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...
Amazon Software Developer interview questions & answers
A Software Developer was asked 1mo agoQ. Could you describe the process for designing a data structure that allows for al...read more
A Software Developer was asked 1mo agoQ. What is MySQL?
A Software Developer was asked 1mo agoQ. What is Java?
Popular interview questions of Software Developer
A Software Developer was asked 1mo agoQ1. Could you describe the process for designing a data structure that allows for al...read more
A Software Developer was asked 1mo agoQ2. What is MySQL?
A Software Developer was asked 1mo agoQ3. What is Java?
Top HR questions asked in Amazon Software Developer
A Software Developer was asked 1mo agoQ1. Tell me about a time you had to get to the root cause of a problem
A Software Developer was asked 5mo agoQ2. What are the short-term and long-term goals for the team or organization?
A Software Developer was asked 5mo agoQ3. Why do you want to work at Amazon?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

