Find an inserted item in a list

In a recent interview I was asked:

If you have 2 lists

lišta LISTB

Each of them has a size of 1000 and contains the same elements 1 - 1000. If an element, N is added to listB, how can you determine the value of this element?

I answered correctly, saying to subtract listB from list A, and the rest would be a value.

He then said that if we just had listB after adding N. How do you determine the value that was added?

I could not answer this question !!!! I should know this, but I just don’t think about it. The hint he gave was to do something similar, as in the first task.

Any suggestions?

+5
source share
4 answers

XOR (N), . .

+2

A sumA. . sumB. sumA sumB. - .

+2

, , , , , "".

, , , .

, , , .

, , , .

If the list randomly inserts an item when you add it, you're out of luck. In this case, you will need to use something as a comparison (the original list).

This is the result of the fact that the object has not only state, but also behavior.

+1
source

Given that most of what I'm doing is based on SQL:

select * 
from listb b
left outer join lista a on (a.id = b.id)
where (a.id is null)
0
source

All Articles