#1131

Maximum of Absolute Value Expression

specialist · 940 · lc medium +32 · verified · 48.6% accepted · 677 likes · top 35%

Description

Given two integer arrays arr1 and arr2 of equal length, return the maximum value of:

|arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|

over all pairs 0 <= i, j < arr1.length.

Example 1:

Input: arr1 = [1,2,3,4], arr2 = [-1,4,5,6]
Output: 13

Example 2:

Input: arr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4]
Output: 20

Code

1
2
3