Given a list of n integers, where every integer in the list exists twice, except for one element, which exist once in the list. For example,
[1 3 3 6 2 7 1 2 7]
I need to find a linear time O(n), and a constant space O(1) algorithm that returns the element which exists once in the list. In the above example, the algorithm should return 6. Note that the list is not provided by any certain order. (The order of the elements in the list is random).
I could solve this problem in O(n) linear time using a dictionary but unfortunately the dictionary requires O(n) space. Any ideas?