3563. Lexicographically Smallest String After Adjacent Removals Hard
1/**
2 * [3563] Lexicographically Smallest String After Adjacent Removals
3 *
4 * You are given a string s consisting of lowercase English letters.
5 * You can perform the following operation any number of times (including zero):
6 *
7 * Remove any pair of adjacent characters in the string that are consecutive in the alphabet, in either order (e.g., 'a' and 'b', or 'b' and 'a').
8 * Shift the remaining characters to the left to fill the gap.
9 *
10 * Return the <span data-keyword="lexicographically-smaller-string">lexicographically smallest</span> string that can be obtained after performing the operations optimally.
11 * Note: Consider the alphabet as circular, thus 'a' and 'z' are consecutive.
12 *
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">s = "abc"</span>
16 * Output: <span class="example-io">"a"</span>
17 * Explanation:
18 *
19 * Remove "bc" from the string, leaving "a" as the remaining string.
20 * No further operations are possible. Thus, the lexicographically smallest string after all possible removals is "a".
21 * </div>
22 * <strong class="example">Example 2:
23 * <div class="example-block">
24 * Input: <span class="example-io">s = "bcda"</span>
25 * Output: <span class="example-io">""</span>
26 * Explanation:
27 *
28 * Remove "cd" from the string, leaving "ba" as the remaining string.
29 * Remove "ba" from the string, leaving "" as the remaining string.
30 * No further operations are possible. Thus, the lexicographically smallest string after all possible removals is "".
31 * </div>
32 * <strong class="example">Example 3:
33 * <div class="example-block">
34 * Input: <span class="example-io">s = "zdce"</span>
35 * Output: <span class="example-io">"zdce"</span>
36 * Explanation:
37 *
38 * Remove "dc" from the string, leaving "ze" as the remaining string.
39 * No further operations are possible on "ze".
40 * However, since "zdce" is lexicographically smaller than "ze", the smallest string after all possible removals is "zdce".
41 * </div>
42 *
43 * Constraints:
44 *
45 * 1 <= s.length <= 250
46 * s consists only of lowercase English letters.
47 *
48 */
49pub struct Solution {}
50
51// problem: https://leetcode.com/problems/lexicographically-smallest-string-after-adjacent-removals/
52// discuss: https://leetcode.com/problems/lexicographically-smallest-string-after-adjacent-removals/discuss/?currentPage=1&orderBy=most_votes&query=
53
54// submission codes start here
55
56impl Solution {
57 pub fn lexicographically_smallest_string(s: String) -> String {
58 String::new()
59 }
60}
61
62// submission codes end
63
64#[cfg(test)]
65mod tests {
66 use super::*;
67
68 #[test]
69 fn test_3563() {
70 }
71}
72Back
© 2026 bowen.ge All Rights Reserved.