-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution1131.java
More file actions
36 lines (31 loc) · 923 Bytes
/
Copy pathSolution1131.java
File metadata and controls
36 lines (31 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package medium;
import java.util.Arrays;
public class Solution1131 {
public int maxAbsValExpr(int[] arr1, int[] arr2) {
int len = arr1.length, max = 0;
Node[] n1 = new Node[len], n2 = new Node[len];
for (int i = 0; i < len; i++) {
n1[i] = new Node(arr1[i], i);
n2[i] = new Node(arr2[i], i);
}
Arrays.sort(n1);
Arrays.sort(n2);
for (int i = 0; i < len; i++) {
for (int j = i + 1; j < len; j++) {
max = Math.max(max, Math.abs(arr1[i] - arr1[j]) + Math.abs(arr2[i] - arr2[j]) + j - i);
}
}
return max;
}
static class Node implements Comparable<Node> {
int val;
int pos;
Node(int val, int pos) {
this.val = val;
this.pos = pos;
}
public int compareTo(Node o) {
return val - o.val;
}
}
}