Mid/SeniorArrayMath

Maximum of Absolute Value Expression

Given two arrays of integers arr1 and arr2 with equal lengths, return the maximum value of:

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

where the maximum is taken over all 0 <= i, j < arr1.length.

Example 1
Inputarr1 = [1,2,3,4], arr2 = [-1,4,5,6]
Output13
The maximum possible value of the expression over all valid pairs of indices is 13.
Example 2
Inputarr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4]
Output20
The maximum possible value of the expression over all valid pairs of indices is 20.

Constraints

  • 2 <= arr1.length == arr2.length <= 40000
  • -10^6 <= arr1[i], arr2[i] <= 10^6

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate