1653. Minimum Deletions to Make String Balanced Medium
1/**
2 * [1653] Minimum Deletions to Make String Balanced
3 *
4 * You are given a string s consisting only of characters 'a' and 'b'.
5 * You can delete any number of characters in s to make s balanced. s is balanced if there is no pair of indices (i,j) such that i < j and s[i] = 'b' and s[j]= 'a'.
6 * Return the minimum number of deletions needed to make s balanced.
7 *
8 * Example 1:
9 *
10 * Input: s = "aababbab"
11 * Output: 2
12 * Explanation: You can either:
13 * Delete the characters at 0-indexed positions 2 and 6 ("aa<u>b</u>abb<u>a</u>b" -> "aaabbb"), or
14 * Delete the characters at 0-indexed positions 3 and 6 ("aab<u>a</u>bb<u>a</u>b" -> "aabbbb").
15 *
16 * Example 2:
17 *
18 * Input: s = "bbaaaaabb"
19 * Output: 2
20 * Explanation: The only solution is to delete the first two characters.
21 *
22 *
23 * Constraints:
24 *
25 * 1 <= s.length <= 10^5
26 * s[i] is 'a' or 'b'.
27 *
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/minimum-deletions-to-make-string-balanced/
32// discuss: https://leetcode.com/problems/minimum-deletions-to-make-string-balanced/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37 pub fn minimum_deletions(s: String) -> i32 {
38 0
39 }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_1653() {
50 }
51}
52
Back
© 2025 bowen.ge All Rights Reserved.