Let x1, x2, ..., xn be credit card numbers.
Please note: since more than half of them belong to the same person, if you count two adjacent numbers, at least one pair of them will belong to the same person.
If you consider all pairs (x1, x2), (x3, x4) .... and consider a subset of pairs in which both elements belong to the same person, most pairs of the same person belong to the person who has the most cards in the first place. Thus, for each pair with the same face, hold one of the card numbers, and pairs of the same faces discard both. Do this recursively and return the last remaining pair with the same face.
You need to complete no more than n comparisons.
NOTE. If n is odd, keep an unpaired number.
Why it works: consider the case when n is even, and person A owns n / 2 + 1 cards. In the worst case scenario, you have exactly one pair in which both cards belong to A. In this case, none of the other pairs belongs to one person (the other pairs contain one card A and another person's card).
Now, to create one matching pair B (non-identity), you also need to create one pair B. Therefore, in all cases, most matching pairs belong to A.
Elkamina
source share