Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Create two frequency maps for both arrays, and find the minimum element among all elements of both arrays.
Check if the sum of frequencies of an element in both arrays is odd, if so return -1
Store the elements that need to be swapped in a vector, and sort it.
Can we reduce swapping cost with the help of minimum element?
Calculate the minimum cost of swapping.