3106. Lexicographically Smallest String After Operations With Constraint Medium
1/**
2 * [3106] Lexicographically Smallest String After Operations With Constraint
3 *
4 * You are given a string s and an integer k.
5 * Define a function distance(s1, s2) between two strings s1 and s2 of the same length n as:
6 *
7 * The sum of the minimum distance between s1[i] and s2[i] when the characters from 'a' to 'z' are placed in a cyclic order, for all i in the range [0, n - 1].
8 *
9 * For example, distance("ab", "cd") == 4, and distance("a", "z") == 1.
10 * You can change any letter of s to any other lowercase English letter, any number of times.
11 * Return a string denoting the <span data-keyword="lexicographically-smaller-string">lexicographically smallest</span> string t you can get after some changes, such that distance(s, t) <= k.
12 *
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">s = "zbbz", k = 3</span>
16 * Output: <span class="example-io">"aaaz"</span>
17 * Explanation:
18 * Change s to "aaaz". The distance between "zbbz" and "aaaz" is equal to k = 3.
19 * </div>
20 * <strong class="example">Example 2:
21 * <div class="example-block">
22 * Input: <span class="example-io">s = "xaxcd", k = 4</span>
23 * Output: <span class="example-io">"aawcd"</span>
24 * Explanation:
25 * The distance between "xaxcd" and "aawcd" is equal to k = 4.
26 * </div>
27 * <strong class="example">Example 3:
28 * <div class="example-block">
29 * Input: <span class="example-io">s = "lol", k = 0</span>
30 * Output: <span class="example-io">"lol"</span>
31 * Explanation:
32 * It's impossible to change any character as k = 0.
33 * </div>
34 *
35 * Constraints:
36 *
37 * 1 <= s.length <= 100
38 * 0 <= k <= 2000
39 * s consists only of lowercase English letters.
40 *
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/lexicographically-smallest-string-after-operations-with-constraint/
45// discuss: https://leetcode.com/problems/lexicographically-smallest-string-after-operations-with-constraint/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50 pub fn get_smallest_string(s: String, k: i32) -> String {
51 String::new()
52 }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_3106() {
63 }
64}
65
Back
© 2025 bowen.ge All Rights Reserved.