#3106

Lexicographically Smallest String After Operations With Constraint

specialist · 680 · lc medium +30 · 62.9% accepted · 165 likes · top 65%

Description

Given a string s and an integer k, define the distance between two equal-length strings as the sum over all positions of the cyclic alphabet distance between corresponding characters (e.g., distance("a", "z") == 1). You may change any characters of s any number of times. Return the lexicographically smallest string t achievable such that distance(s, t) <= k.

Code

1
2
3