Minimum Absolute Sum Difference
You are given two positive integer arrays nums1 and nums2, both of length n.
The absolute sum difference of arrays nums1 and nums2 is defined as the sum of |nums1[i] - nums2[i]| for each 0 <= i < n (0-indexed).
You can replace at most one element of nums1 with any other element in nums1 to minimize the absolute sum difference.
Return the minimum absolute sum difference after replacing at most one element in the array nums1. Since the answer may be large, return it modulo 10^9 + 7.
|x| is defined as:
xifx >= 0, or-xifx < 0.
Example 1
Input
nums1 = [1,7,5], nums2 = [2,3,5]Output
3There are two possible optimal solutions: replace the second element with the first or third element, both yielding an absolute sum difference of 3.
Example 2
Input
nums1 = [2,4,6,8,10], nums2 = [2,4,6,8,10]Output
0nums1 is equal to nums2, so no replacement is needed and the absolute sum difference is 0.Constraints
- n == nums1.length
- n == nums2.length
- 1 <= n <= 10^5
- 1 <= nums1[i], nums2[i] <= 10^5