Quant Memo
Coding/●●●●●

Find the id that appears once among triples

A gateway now logs every order message three times (send, ack, echo), so each id should appear exactly three times. One id appears only once because two of its copies were dropped.

ids = [2, 2, 3, 2]      # 2 appears three times, 3 appears once
-> 3

Find the lone id in O(n)O(n) time and O(1)O(1) space. Assume non-negative ids.

Show a hint

XOR cancels pairs, not triples: xxx=xx \oplus x \oplus x = x, so XOR-ing everything leaves the singleton tangled with the tripled ids. Think one bit column at a time instead.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions