Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Make Array Equal II

Try to solve the Minimum Operations to Make Array Equal II problem.

Statement

You are given two integer arrays nums1 and nums2 of length n, alongside an integer k.

In a single operation, you can choose two indices i and j where 0≤0 \leq i, j << n, increment nums1[i] by k, and decrement nums1[j] by k.

Return the minimum number of operations needed to make nums1 identical to nums2. If it is impossible to make both arrays equal, return −1-1.

Note: Two arrays are considered equal if nums1[i] == nums2[i] for all 0≤0 \leq i << n.

Constraints:

  • n ==== nums1.length ==== nums2.length

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

  • 0≤0 \leq nums1[i], nums2[j] ≤109\leq 10^9

  • 0≤0 \leq k ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Make Array Equal II

Try to solve the Minimum Operations to Make Array Equal II problem.

Statement

You are given two integer arrays nums1 and nums2 of length n, alongside an integer k.

In a single operation, you can choose two indices i and j where 0≤0 \leq i, j << n, increment nums1[i] by k, and decrement nums1[j] by k.

Return the minimum number of operations needed to make nums1 identical to nums2. If it is impossible to make both arrays equal, return −1-1.

Note: Two arrays are considered equal if nums1[i] == nums2[i] for all 0≤0 \leq i << n.

Constraints:

  • n ==== nums1.length ==== nums2.length

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

  • 0≤0 \leq nums1[i], nums2[j] ≤109\leq 10^9

  • 0≤0 \leq k ≤105\leq 10^5