Skip to content

re: Can you solve this without using extra memory? VIEW POST


To avoid using extra memory, the only way this could work is if you apply an arithmetic or logical operation as you iterate through the list. You'd need an operation that yields zero when it is applied between two same values (you want all of the duplicated values to cancel each other out). The operation would also have to be commutative and associative. There's only one operation I can think of that fits the bill, and it seems to come up when this kind of tricky problem is involved: xor.

code of conduct - report abuse