package leetcode;

/**
 * https://leetcode.com/problems/sum-of-beauty-of-all-substrings/
 */
public class Problem1781 {
    public int beautySum(String s) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1781 prob = new Problem1781();
        System.out.println(prob.beautySum("aabcb")); // 5
        System.out.println(prob.beautySum("aabcbaa")); // 17
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -188,250 +188,900 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1781 prob = new Problem1781();%0A        System.out.println(prob.beautySum(%22aabcb%22)); // 5%0A        System.out.println(prob.beautySum(%22aabcbaa%22)); // 17
+int%5B%5D%5B%5D counts = new int%5Bs.length()%5D%5B26%5D;%0A        for (int i = 0; i %3C s.length(); i++) %7B%0A            if (i != 0) %7B%0A                counts%5Bi%5D = Arrays.copyOf(counts%5Bi - 1%5D, 26);%0A            %7D%0A            counts%5Bi%5D%5Bs.charAt(i) - 'a'%5D++;%0A        %7D%0A        int answer = 0;%0A        for (int i = 0; i %3C s.length(); i++) %7B%0A            for (int j = i; j %3C s.length(); j++) %7B%0A                int min = Integer.MAX_VALUE;%0A                int max = Integer.MIN_VALUE;%0A                for (int k = 0; k %3C counts%5Bj%5D.length; k++) %7B%0A                    int count = counts%5Bj%5D%5Bk%5D - (i - 1 %3C 0 ? 0 : counts%5Bi - 1%5D%5Bk%5D);%0A                    if (count == 0) %7B%0A                        continue;%0A                    %7D%0A                    min = Math.min(min, count);%0A                    max = Math.max(max, count);%0A                %7D%0A                answer += max - min;%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 1781