Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Equalize Arrays Using Swaps

Try to solve the Minimum Cost to Equalize Arrays Using Swaps problem.

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 ≤8imes104\leq 8 imes 10^4

  • 1≤1 \leq nums1[i], nums2[i] ≤8imes104\leq 8 imes 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Equalize Arrays Using Swaps

Try to solve the Minimum Cost to Equalize Arrays Using Swaps problem.

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 ≤8imes104\leq 8 imes 10^4

  • 1≤1 \leq nums1[i], nums2[i] ≤8imes104\leq 8 imes 10^4