Minimum Deletions to Make String Balanced LeetCode solution in Java
1class Solution {2public int minimumDeletions(String s) {3// ideal case : bbbbbbbbb4int[] dp = new int[s.length() + 1];5int idx = 1;6int bCount = 0;78for (int i = 0; i < s.length(); i++) {9if (s.charAt(i) == 'a') {10dp[idx] = Math.min(dp[idx - 1] + 1, bCount);11} else {12dp[idx] = dp[idx - 1];13bCount++;14}1516idx++;17}18return dp[s.length()];19}20}