Replace With the Previous, Minimize Codeforces Solution | Codeforces Problem Solution 2022
You are given a string of lowercase Latin letters.
The following operation can be used:
- select one character (from 'a' to 'z') that occurs at least once in the string. And replace all such characters in the string with the previous one in alphabetical order on the loop. For example, replace all 'c' with 'b' or replace all 'a' with 'z'.
And you are given the integer — the maximum number of operations that can be performed. Find the minimum lexicographically possible string that can be obtained by performing no more than operations.
The string is lexicographically smaller than the string if there exists an index () such that , , ..., , but .
The first line contains a single integer () —the number of test cases in the test.
This is followed by descriptions of the test cases.
The first line of each test case contains two integers and (, ) — the size of the string and the maximum number of operations that can be performed on the string .
The second line of each test case contains a string of length consisting of lowercase Latin letters.
It is guaranteed that the sum over all test cases does not exceed .
For each test case, output the lexicographically minimal string that can be obtained from the string by performing no more than operations.
Join Now for Solution:-
No comments:
Post a Comment