LeetCode 1818. 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 109 + 7
.
|x|
is defined as:
x
ifx >= 0
, or-x
ifx < 0
.
Example 1:
Example 2:
Example 3:
Constraints:
n == nums1.length
n == nums2.length
1 <= n <= 10^5
1 <= nums1[i], nums2[i] <= 10^5
Solution
PreviousLeetCode 1817. Finding the Users Active MinutesNextLeetCode 1819. Number of Different Subsequences GCDs
Last updated