Tap here to switch tabs
Problem
Submissions

Problem: Minimum Absolute Sum Difference

med
30 min
Try to solve the Minimum Absolute Sum Difference problem.

Statement

You are given two positive integer arrays nums1 and nums2, both of length n.

The absolute sum difference between two arrays is defined as the sum of ∣|nums1[i] −- nums2[i]∣| for all 0≤0 \leq i <n< n.

You can replace at most one element of nums1 with any other element present in nums1 to minimize the absolute sum difference.

Return the minimum absolute sum difference after replacing at most one element. Since the answer may be large, return it modulo 109+710^9 + 7.

Constraints:

  • n ==== nums1.length

  • n ==== nums2.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq nums1[i], nums2[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Absolute Sum Difference

med
30 min
Try to solve the Minimum Absolute Sum Difference problem.

Statement

You are given two positive integer arrays nums1 and nums2, both of length n.

The absolute sum difference between two arrays is defined as the sum of ∣|nums1[i] −- nums2[i]∣| for all 0≤0 \leq i <n< n.

You can replace at most one element of nums1 with any other element present in nums1 to minimize the absolute sum difference.

Return the minimum absolute sum difference after replacing at most one element. Since the answer may be large, return it modulo 109+710^9 + 7.

Constraints:

  • n ==== nums1.length

  • n ==== nums2.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq nums1[i], nums2[i] ≤105\leq 10^5