a to z sit on a wheel, so a comes right after z. Changing one letter into another costs the number of steps between them around the wheel, going the shorter way. For example, c → a costs 2, and so does y → a (via z).
You get a string text and a budget budget. You may change any letters of text as long as the total cost of all changes is at most budget.
Return the lexicographically smallest string you can end up with.text="ybcz", budget=4 → 'aabz'
y → a costs 2 steps (via z), b → a costs 1 more. One step is left, so c becomes b. Nothing remains for z.
text="hello", budget=20 → 'aaclo'
h → a costs 7 and e → a costs 4, leaving 9. Turning l into a would take 11, so l moves down by 9 and becomes c.
text="mno", budget=0 → 'mno'
With a zero budget the string stays as it is.
text consists of lowercase English letterstext="ybcz", budget=4
'aabz'
Run checks the first 3 tests in your browser. Submit checks all 113 tests on the server, hidden ones included.