Class Solution
-
- All Implemented Interfaces:
public final class Solution3106 - Lexicographically Smallest String After Operations With Constraint.
Medium
You are given a string
sand an integerk.Define a function <code>distance(s<sub>1</sub>, s<sub>2</sub>)</code> between two strings <code>s<sub>1</sub></code> and <code>s<sub>2</sub></code> of the same length
nas:The sum of the minimum distance between <code>s<sub>1</sub>i</code> and <code>s<sub>2</sub>i</code> when the characters from
'a'to'z'are placed in a cyclic order, for alliin the range[0, n - 1].
For example,
distance("ab", "cd") == 4, anddistance("a", "z") == 1.You can change any letter of
sto any other lowercase English letter, any number of times.Return a string denoting the lexicographically smallest string
tyou can get after some changes, such thatdistance(s, t) <= k.Example 1:
Input: s = "zbbz", k = 3
Output: "aaaz"
Explanation:
Change
sto"aaaz". The distance between"zbbz"and"aaaz"is equal tok = 3.Example 2:
Input: s = "xaxcd", k = 4
Output: "aawcd"
Explanation:
The distance between "xaxcd" and "aawcd" is equal to k = 4.
Example 3:
Input: s = "lol", k = 0
Output: "lol"
Explanation:
It's impossible to change any character as
k = 0.Constraints:
1 <= s.length <= 1000 <= k <= 2000sconsists only of lowercase English letters.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final StringgetSmallestString(String s, Integer k)-
-
Method Detail
-
getSmallestString
final String getSmallestString(String s, Integer k)
-
-
-
-