#K83822. Minimum Swaps to Make Arrays Identical
Minimum Swaps to Make Arrays Identical
Minimum Swaps to Make Arrays Identical
In this problem, you are given two arrays A and B of length (n). Your task is to determine the minimum number of swaps needed to make array A identical to array B. During each swap, you may swap any two elements in array A. However, if it is not possible to transform A into B (i.e. the two arrays do not contain the same multiset of elements), output -1.
Note: It is guaranteed that all elements in the arrays are integers and, for the purpose of this problem, you may assume the arrays contain distinct elements, although the solution should work correctly when this condition may not hold.
inputFormat
The first line contains an integer (n) representing the number of elements in the arrays. The second line contains (n) space-separated integers representing the array A. The third line contains (n) space-separated integers representing the array B.
outputFormat
Output a single integer representing the minimum number of swaps required to transform array A into array B. If it is not possible, output -1.## sample
4
1 2 3 4
2 1 4 3
2
</p>