package leetcode;

/**
 * https://leetcode.com/problems/minimum-deletion-cost-to-avoid-repeating-letters/
 */
public class Problem1578 {
    public int minCost(String s, int[] cost) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1578 prob = new Problem1578();
        System.out.println(prob.minCost("abaac", new int[]{1,2,3,4,5})); // 3
        System.out.println(prob.minCost("abc", new int[]{1,2,3})); // 0
        System.out.println(prob.minCost("aabaa", new int[]{1,2,3,4,1})); // 2
        System.out.println(prob.minCost("aabaaa", new int[]{1,2,3,4,1,5})); // 6
    }
}

@@ -189,15 +189,23 @@
     
-// TODO
+int answer = 0;
 %0A   
@@ -213,22 +213,23 @@
     
-return
+int i =
  0;%0A    
 %7D%0A%0A 
@@ -228,410 +228,476 @@
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1578 prob = new Problem1578();%0A        System.out.println(prob.minCost(%22abaac%22, new int%5B%5D%7B1,2,3,4,5%7D)); // 3%0A        System.out.println(prob.minCost(%22abc%22, new int%5B%5D%7B1,2,3%7D)); // 0%0A        System.out.println(prob.minCost(%22aabaa%22, new int%5B%5D%7B1,2,3,4,1%7D)); // 2%0A        System.out.println(prob.minCost(%22aabaaa%22, new int%5B%5D%7B1,2,3,4,1,5%7D)); // 6
+while (i %3C s.length()) %7B%0A            int max = cost%5Bi%5D;%0A            int sum = cost%5Bi%5D;%0A            int count = 1;%0A            while (i + 1 %3C s.length() && s.charAt(i) == s.charAt(i + 1)) %7B%0A                max = Math.max(max, cost%5Bi + 1%5D);%0A                sum += cost%5Bi + 1%5D;%0A                count++;%0A                i++;%0A            %7D%0A            if (count %3E 1) %7B%0A                answer += sum - max;%0A            %7D%0A            i++;%0A        %7D%0A        return answer;
 %0A   

Solve problem 1578