I have the following arrays:
A = [1,2,3,4,5]
B = [2,6,7,1]
I want to find the disjoint elements, which are as follows:
output = [3,4,5,6,7]
I was able to achieve this as follows,
output = A + B - (A & B)
but it is inefficient, as I'm adding two arrays and then removing common elements. It is similar to finding non-intersecting elements. Can I do it better than this? If so, how?
How about just selecting elements in A not in B and elements in B not in A.
(A - B) + (B - A)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With