Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Equalize Arrays Using Swaps

Minimum Cost to Equalize Arrays Using Swaps asks you to make two integer arrays identical by rearranging within arrays for free and swapping across them at cost one, or return -1 if impossible.

Statement

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

You can perform the following operations any number of times in any order:

  • Swap any two elements within the same array at a cost of 00.

  • Swap an element nums1[i] with an element nums2[j] at a cost of 11.

Return the minimum total cost required to make nums1 and nums2 identical. If it is impossible to make the two arrays identical, return −1-1.

Constraints:

  • 2≤n==2 \leq n == nums1.length ==== nums2.length ≤8×104\leq 8 \times 10^4

  • 1≤1 \leq nums1[i], nums2[i] ≤8×104\leq 8 \times 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Equalize Arrays Using Swaps

Minimum Cost to Equalize Arrays Using Swaps asks you to make two integer arrays identical by rearranging within arrays for free and swapping across them at cost one, or return -1 if impossible.

Statement

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

You can perform the following operations any number of times in any order:

  • Swap any two elements within the same array at a cost of 00.

  • Swap an element nums1[i] with an element nums2[j] at a cost of 11.

Return the minimum total cost required to make nums1 and nums2 identical. If it is impossible to make the two arrays identical, return −1-1.

Constraints:

  • 2≤n==2 \leq n == nums1.length ==== nums2.length ≤8×104\leq 8 \times 10^4

  • 1≤1 \leq nums1[i], nums2[i] ≤8×104\leq 8 \times 10^4