Skip to content

Commit 0f4d4c8

Browse files
authored
Create 1131-maximum-of-absolute-value-expression.js
1 parent 1c11c80 commit 0f4d4c8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {number[]} arr1
3+
* @param {number[]} arr2
4+
* @return {number}
5+
*/
6+
var maxAbsValExpr = function(arr1, arr2) {
7+
let n = arr1.length;
8+
let combs = [
9+
[1,1],[1,-1],[-1,1],[-1,-1]
10+
];
11+
let result = -Infinity;
12+
for(let [p,q] of combs) {
13+
let max = -Infinity, min = Infinity;
14+
for(let i=0; i < n; i++) {
15+
let value = (p * arr1[i]) + (q * arr2[i]) + i;
16+
max = Math.max(max,value);
17+
min = Math.min(min,value);
18+
};
19+
result = Math.max(result, max-min);
20+
};
21+
return result;
22+
};
23+

0 commit comments

Comments
 (0)