lambda1@tg says to YSITD
We can readily supply an algorithm for (1) if we are acquainted with the ubiquitous set data structure. let s be an empty set for i in list: if i in s: return i s.insert(i) However, we can do better. There is a O(n) time O(1) memory algorithm hidden in the wild, which is quite nontrivial. However, everyone with a basic understanding of data structure can devise the algorithm outlined above immediately.