
Distinguishing extra element from two arrays?
1 Expert Answer

Tridip C. answered 08/05/20
4+ years of Experience in Academic Research and Tutoring in Logic
Let's call the arrays A and B and let their unique elements be a and b, respectively.
First, take the sums of both arrays and subtract one from the other; since everything else cancels,
sum(A) - sum(B) = a - b = s.
Then, multiply the elements of both arrays and divide one by the other. Again, things cancel, so
mult(A) / mult(B) = a / b = r.
Now, from these, we get:
a = rb, so rb - b = s or b = s / (r - 1) and then a = rs / (r - 1)
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
i vote for sorting. Quicksort is efficient07/13/19