3868. Minimum Cost to Equalize Arrays Using Swaps
You are given two integer arrays
nums1andnums2of sizen.You can perform the following two operations any number of times on these two arrays:
- Swap within the same array: Choose two indices
iandj. Then, choose either to swapnums1[i]andnums1[j], ornums2[i]andnums2[j]. This operation is free of charge.- Swap between two arrays: Choose an index
i. Then, swapnums1[i]andnums2[i]. This operation incurs a cost of 1.Return an integer denoting the minimum cost to make
nums1andnums2identical. If this is not possible, return -1.
1 | class Solution { |