3561. Resulting String After Adjacent Removals Medium
1/**
2 * [3561] Resulting String After Adjacent Removals
3 *
4 * You are given a string s consisting of lowercase English letters.
5 * You must repeatedly perform the following operation while the string s has at least two consecutive characters:
6 *
7 * Remove the leftmost 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 resulting string after no more operations can be performed.
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">"c"</span>
17 * Explanation:
18 *
19 * Remove "ab" from the string, leaving "c" as the remaining string.
20 * No further operations are possible. Thus, the resulting string after all possible removals is "c".
21 * </div>
22 * <strong class="example">Example 2:
23 * <div class="example-block">
24 * Input: <span class="example-io">s = "adcb"</span>
25 * Output: <span class="example-io">""</span>
26 * Explanation:
27 *
28 * Remove "dc" from the string, leaving "ab" as the remaining string.
29 * Remove "ab" from the string, leaving "" as the remaining string.
30 * No further operations are possible. Thus, the resulting 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 = "zadb"</span>
35 * Output: <span class="example-io">"db"</span>
36 * Explanation:
37 *
38 * Remove "za" from the string, leaving "db" as the remaining string.
39 * No further operations are possible. Thus, the resulting string after all possible removals is "db".
40 * </div>
41 *
42 * Constraints:
43 *
44 * 1 <= s.length <= 10^5
45 * s consists only of lowercase English letters.
46 *
47 */
48pub struct Solution {}
49
50// problem: https://leetcode.com/problems/resulting-string-after-adjacent-removals/
51// discuss: https://leetcode.com/problems/resulting-string-after-adjacent-removals/discuss/?currentPage=1&orderBy=most_votes&query=
52
53// submission codes start here
54
55impl Solution {
56 pub fn resulting_string(s: String) -> String {
57 String::new()
58 }
59}
60
61// submission codes end
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
68 fn test_3561() {
69 }
70}
71Back
© 2026 bowen.ge All Rights Reserved.