package leetcode;

/**
 * https://leetcode.com/problems/maximum-of-absolute-value-expression/
 */
public class Problem1131 {
    public int maxAbsValExpr(int[] arr1, int[] arr2) {
        int answer = 0;
        for (int i = 0; i < arr1.length; i++) {
            for (int j = i + 1; j < arr2.length; j++) {
                int value = Math.abs(arr1[i] - arr1[j]) + Math.abs(arr2[i] - arr2[j]) + Math.abs(i - j);
                answer = Math.max(answer, value);
            }
        }
        return answer;
    }

    public static void main(String[] args) {
        Problem1131 prob = new Problem1131();
        System.out.println(prob.maxAbsValExpr(new int[]{1, 2, 3, 4}, new int[]{-1, 4, 5, 6})); // 13
        System.out.println(prob.maxAbsValExpr(new int[]{1, -2, -5, 0, 10}, new int[]{0, -2, -1, -7, -4})); // 20
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -215,72 +215,377 @@
 int 
-answer = 0;%0A        for (int i = 0; i %3C arr1.length; i++) %7B%0A    
+size = arr1.length;%0A        int values%5B%5D%5B%5D = new int%5B8%5D%5Bsize%5D;%0A        for (int i = 0; i %3C size; i++) %7B%0A            values%5B0%5D%5Bi%5D += arr1%5Bi%5D + arr2%5Bi%5D + i;%0A        %7D%0A        for (int i = 0; i %3C size; i++) %7B%0A            values%5B1%5D%5Bi%5D += arr1%5Bi%5D + arr2%5Bi%5D - i;%0A        %7D%0A        for (int i = 0; i %3C size; i++) %7B%0A            values%5B2%5D%5Bi%5D += arr1%5Bi%5D - arr2%5Bi%5D + i;%0A        %7D%0A
     
@@ -601,114 +601,476 @@
 int 
-j = i + 1; j %3C arr2.length; j++) %7B%0A                int value = Math.abs(arr1%5Bi%5D - arr1%5Bj%5D) + Math.abs(arr2
+i = 0; i %3C size; i++) %7B%0A            values%5B3%5D%5Bi%5D += arr1%5Bi%5D - arr2%5Bi%5D - i;%0A        %7D%0A        for (int i = 0; i %3C size; i++) %7B%0A            values%5B4%5D%5Bi%5D += -arr1%5Bi%5D + arr2%5Bi%5D + i;%0A        %7D%0A        for (int i = 0; i %3C size; i++) %7B%0A            values%5B5%5D%5Bi%5D += -arr1%5Bi%5D + arr2%5Bi%5D - i;%0A        %7D%0A        for (int i = 0; i %3C size; i++) %7B%0A            values%5B6%5D%5Bi%5D += -arr1%5Bi%5D - arr2%5Bi%5D + i;%0A        %7D%0A        for (int i = 0; i %3C size; i++) %7B%0A            values%5B7%5D%5Bi%5D += -arr1
 %5Bi%5D 
@@ -1080,94 +1080,412 @@
 rr2%5B
-j%5D) + Math.abs(i - j);%0A                answer = Math.max(answer, value);%0A            %7D
+i%5D - i;%0A        %7D%0A        int answer = 0;%0A        for (int%5B%5D nums : values) %7B%0A            answer = Math.max(answer, getValue(nums));%0A        %7D%0A        return answer;%0A    %7D%0A%0A    private static int getValue(int%5B%5D nums) %7B%0A        int min = nums%5B0%5D;%0A        int max = nums%5B0%5D;%0A        for (int i = 1; i %3C nums.length; i++) %7B%0A            min = Math.min(min, nums%5Bi%5D);%0A            max = Math.max(max, nums%5Bi%5D);
 %0A   
@@ -1498,38 +1498,41 @@
 %0A        return 
-answer
+max - min
 ;%0A    %7D%0A%0A    pub

Solve problem 1131