<p>Given two arrays of integers with equal lengths, return the maximum value of:</p>

<p><code>|arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|</code></p>

<p>where the maximum is taken over all <code>0 &lt;= i, j &lt; arr1.length</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> arr1 = [1,2,3,4], arr2 = [-1,4,5,6]
<strong>Output:</strong> 13
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> arr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4]
<strong>Output:</strong> 20
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>2 &lt;= arr1.length == arr2.length &lt;= 40000</code></li>
	<li><code>-10^6 &lt;= arr1[i], arr2[i] &lt;= 10^6</code></li>
</ul>

class Solution:
    def findMaxDiff(self, nums: List[int]) -> int:
        min_val = nums[0]
        max_diff = 0
        for num in nums[1:]:
            diff = num - min_val
            max_diff = max(max_diff, diff)
            min_val = min(num, min_val)
        return max_diff

    def maxAbsValExpr(self, arr1: List[int], arr2: List[int]) -> int:
        debug = False
        # A_i = a1_i + a2_i
        # B_i = a1_i - a2_i
        # = max(a1_i - a1_j + a2_i - a2_j,   A_i - A_j + i - j
        #       a1_i - a1_j - a2_i + a2_j,   B_i - B_j + i - j
        #       a1_j - a1_i + a2_i - a2_j,   -B_i + B_j + i - j
        #       a1_j - a1_i - a2_i + a2_j,   -A_i + A_j + i - j
        #        ...  ) + i - j       
        A = [a1 + a2 for a1, a2 in zip(arr1, arr2)]
        B = [a1 - a2 for a1, a2 in zip(arr1, arr2)]
        n = len(arr1)
        if debug:
            print([A[i] + i for i in range(n)])
        diff_1 = self.findMaxDiff([A[i] + i for i in range(n)])
        diff_2 = self.findMaxDiff([B[i] + i for i in range(n)])
        diff_3 = self.findMaxDiff([-B[i] + i for i in range(n)])
        diff_4 = self.findMaxDiff([-A[i] + i for i in range(n)])
        if debug:
            print(diff_1, diff_2, diff_3, diff_4)
        return max(diff_1, diff_2, diff_3, diff_4)

        

        
25900