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.