3223. Minimum Length of String After Operations Medium
1/**
2 * [3223] Minimum Length of String After Operations
3 *
4 * You are given a string s.
5 * You can perform the following process on s any number of times:
6 *
7 * Choose an index i in the string such that there is at least one character to the left of index i that is equal to s[i], and at least one character to the right that is also equal to s[i].
8 * Delete the closest character to the left of index i that is equal to s[i].
9 * Delete the closest character to the right of index i that is equal to s[i].
10 *
11 * Return the minimum length of the final string s that you can achieve.
12 *
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">s = "abaacbcbb"</span>
16 * Output: <span class="example-io">5</span>
17 * Explanation:<br />
18 * We do the following operations:
19 *
20 * Choose index 2, then remove the characters at indices 0 and 3. The resulting string is s = "bacbcbb".
21 * Choose index 3, then remove the characters at indices 0 and 5. The resulting string is s = "acbcb".
22 * </div>
23 * <strong class="example">Example 2:
24 * <div class="example-block">
25 * Input: <span class="example-io">s = "aa"</span>
26 * Output: <span class="example-io">2</span>
27 * Explanation:<br />
28 * We cannot perform any operations, so we return the length of the original string.
29 * </div>
30 *
31 * Constraints:
32 *
33 * 1 <= s.length <= 2 * 10^5
34 * s consists only of lowercase English letters.
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/minimum-length-of-string-after-operations/
40// discuss: https://leetcode.com/problems/minimum-length-of-string-after-operations/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn minimum_length(s: String) -> i32 {
46 0
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_3223() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.