So here is the riddle:
There is a list of numbers, where each number appears in the list twice. Except there is one number that appears once. I give you the list one number at a time.
The question is: can you find out what the number is that appears only once?
You can’t save the whole list and then look at it later. You can only store at most one number. In jargon, you must do it in constant space.
For example if I gave you the list 1,3,5,3,8,5,1, then 8 is the number that only appears once.
So the condensed version of riddle is:
Given a list of numbers read off one by one where each number appears twice, and one number that appears once, can you find the number that appears once by only storing one intermediate number?