Python easy solution
\n       \n\t\tpossible_sol={A[0],B[0]}  #For a solution to exist all values should be either A[0] or B[0] after swapping\n        l=len(A)\n        for i in po
\n       \n\t\tpossible_sol={A[0],B[0]}  #For a solution to exist all values should be either A[0] or B[0] after swapping\n        l=len(A)\n        for i in possible_sol: #check both the cases\n            Aswap=Bswap=0  #set number of swaps for A and B to 0\n\t\t\tflag=0\n            for j in range(l):\n                if A[j]==B[j]==i: # if both are same no need to swap\n                    pass\n                elif A[j]==i:  #if only B[j] is different it can be swapped \n                    Bswap+=1\n                elif B[j]==i: #if only A[j] is different it can be swapped\n                    Aswap+=1\n                else:  #if both are different, then solution does not exist for current value of i\n\t\t\t\t\tflag=1\n                    break\n            if flag==0:\n                return min(Aswap,Bswap) #return the minimum number of swaps\n        return -1 #return -1 if solution does not exist in both the cases\n
['Python3']