Minimum number of swaps in array1 and array2 to make their respective sum even

There were given 2 arrays of size n and m. We have to find the minimum number of swaps to make sum of array1 even and array2 even. If not possible return -1 and if their respective sums are even return 0.

Test case 1 :

array1 = {3,3,6,2} sum1 = 14(even)
array2 = {4,1,6,3} sum2 = 14(even)

As both sum1 and sum2 are even the output is 0, as indicating no swaps.

Test case 2:

array1 = {1,4, 20, 2}
array2 = {5, 9, 6, 3}

output is 1, as indicating no swaps.

@danishrehman288 What is the doubt behind this question?

I am not able to solve this question, this question was asked to me by tech giant. Can you send/post me the solution.

@danishrehman288 Follow the given link-


This link will provide you with a solution having different constraints to the problem but will guide you to the solution.