In a recent interview I was asked:
If you have 2 lists
listA
listB
Each are the size 1000 and contain the same elements 1 – 1000. If an element, N is added to listB how can you determine the value of that element?
I responded correctly by saying to subtract listB from listA and the remainder would be the value.
Then he said what if we just have listB after N was added. How would you determine the value that was added?
I failed to answer this!!!! I should know it but I just cant think of it. The hint he gave was to do something similar as I did in the first problem.
Any suggestions?
You can exclusive XOR both lists and whatever is new (N) you will have it. This is the answer to the first question.