Distinguishing extra element from two arrays?

One of my friend was asked this question in an interview - - You have given two integer arrays each of size 10. - Both contains 9 equal elements (say 1 to 9) - Only one element is different. How will you find the different element? What are different approaches you can take? > One simple but lengthy approach would be - sort both arrays,go on comparing each element,on false comparison, you'll get your result. So what are different approaches for this? Specify logic as its expected in an interview. Not expecting a particular code in a specific language. Pseudo code will suffice. (Please submit one approach per answer) > My purpose of asking this question is, its OK when array sizes are small.But when array size increases, you must think of a very efficient n faster way.Its never desirable to use comparisons in such case.

Patrick B.

tutor
i vote for sorting. Quicksort is efficient
Report

07/13/19

By:

Tutor
4.9 (186)

4+ years of Experience in Academic Research and Tutoring in Logic

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.