2734. Lexicographically Smallest String After Substring Operation Medium
1/**
2 * [2734] Lexicographically Smallest String After Substring Operation
3 *
4 * Given a string s consisting of lowercase English letters. Perform the following operation:
5 *
6 * Select any non-empty <span data-keyword="substring-nonempty">substring</span> then replace every letter of the substring with the preceding letter of the English alphabet. For example, 'b' is converted to 'a', and 'a' is converted to 'z'.
7 *
8 * Return the <span data-keyword="lexicographically-smaller-string">lexicographically smallest</span> string after performing the operation.
9 *
10 * <strong class="example">Example 1:
11 * <div class="example-block">
12 * Input: <span class="example-io">s = "cbabc"</span>
13 * Output: <span class="example-io">"baabc"</span>
14 * Explanation:
15 * Perform the operation on the substring starting at index 0, and ending at index 1 inclusive.
16 * </div>
17 * <strong class="example">Example 2:
18 * <div class="example-block">
19 * Input: <span class="example-io">s = "aa"</span>
20 * Output: <span class="example-io">"az"</span>
21 * Explanation:
22 * Perform the operation on the last letter.
23 * </div>
24 * <strong class="example">Example 3:
25 * <div class="example-block">
26 * Input: <span class="example-io">s = "acbbc"</span>
27 * Output: <span class="example-io">"abaab"</span>
28 * Explanation:
29 * Perform the operation on the substring starting at index 1, and ending at index 4 inclusive.
30 * </div>
31 * <strong class="example">Example 4:
32 * <div class="example-block">
33 * Input: <span class="example-io">s = "leetcode"</span>
34 * Output: <span class="example-io">"kddsbncd"</span>
35 * Explanation:
36 * Perform the operation on the entire string.
37 * </div>
38 *
39 * Constraints:
40 *
41 * 1 <= s.length <= 3 * 10^5
42 * s consists of lowercase English letters
43 *
44 */
45pub struct Solution {}
46
47// problem: https://leetcode.com/problems/lexicographically-smallest-string-after-substring-operation/
48// discuss: https://leetcode.com/problems/lexicographically-smallest-string-after-substring-operation/discuss/?currentPage=1&orderBy=most_votes&query=
49
50// submission codes start here
51
52impl Solution {
53 pub fn smallest_string(s: String) -> String {
54 String::new()
55 }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn test_2734() {
66 }
67}
68
Back
© 2025 bowen.ge All Rights Reserved.