Quant Memo
Coding/●●●●●

Find the unpaired message with XOR

A gateway logs every order message twice (send and echo), so each message id should appear exactly twice in the log. One id appears only once, its echo was dropped.

ids = [4, 1, 2, 1, 2]
-> 4

Find the unpaired id in O(n)O(n) time and O(1)O(1) space. A hash set works but costs O(n)O(n) memory, the interviewer wants the bit trick.

Show a hint

What is xxx \oplus x? What is x0x \oplus 0? Is \oplus order-sensitive?

Your answer

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

More Coding questions