package leetcode;

/**
 * https://leetcode.com/problems/minimum-deletions-to-make-string-balanced/
 */
public class Problem1643 {
    public int minimumDeletions(String s) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1643 prob = new Problem1643();
        System.out.println(prob.minimumDeletions("aababbab")); // 2
        System.out.println(prob.minimumDeletions("bbaaaaabb")); // 2
        System.out.println(prob.minimumDeletions("bbbbbbbaaaaabb")); // 5
        System.out.println(prob.minimumDeletions("abbbbbbbbbbbb")); // 0
        System.out.println(prob.minimumDeletions("abab")); // 1
        System.out.println(prob.minimumDeletions("abaababa")); // 3
        System.out.println(prob.minimumDeletions("bbb")); // 0
        System.out.println(prob.minimumDeletions("abbbababbab")); // 3
        System.out.println(prob.minimumDeletions("aabbab")); // 1
    }
}

@@ -179,747 +179,484 @@
     
-// TODO%0A        return 0;
+int countA = 0;%0A        for (char c : s.toCharArray()) %7B
 %0A    
-%7D%0A%0A
+ 
     
-public static void main(String%5B%5D args) %7B%0A        Problem1643 prob = new Problem1643();%0A        System.out.println(prob.minimumDeletions(%22aababbab%22)); // 2%0A        System.out.println(prob.minimumDeletions(%22bbaaaaabb%22)); // 2%0A        System.out.println(prob.minimumDeletions(%22bbbbbbbaaaaabb%22)); // 5%0A        System.out.println(prob.minimumDeletions(%22abbbbbbbbbbbb%22)); // 0%0A        System.out.println(prob.minimumDeletions(%22abab%22)); // 1%0A        System.out.println(prob.minimumDeletions(%22abaababa%22)); // 3%0A        System.out.println(prob.minimumDeletions(%22bbb%22)); // 0%0A        System.out.println(prob.minimumDeletions(%22abbbababbab%22)); // 3%0A        System.out.println(prob.minimumDeletions(%22aabbab%22)); // 1
+   if (c == 'a') %7B%0A                countA++;%0A            %7D%0A        %7D%0A        int answer = countA;%0A        int countB = 0;%0A        for (char c : s.toCharArray()) %7B%0A            if (c == 'a') %7B%0A                countA--;%0A            %7D else %7B%0A                countB++;%0A            %7D%0A            if (countA + countB %3C answer) %7B%0A                answer = countA + countB;%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 1643