Quant Memo
Coding/●●●●●

Find the injected order id with XOR

A risk monitor keeps two logs of order ids. Log b is supposed to be a reshuffled copy of log a, but a rogue process injected exactly one extra order, so b contains every id in a (same multiplicities) plus one additional id.

a = [5, 2, 9]
b = [2, 9, 5, 7]        # same ids as a, plus 7
-> 7

Find the injected id in O(n)O(n) time and O(1)O(1) space. A frequency map works but costs O(n)O(n) memory; use the bit trick.

Show a hint

What happens if you XOR every id in both logs into one accumulator?

Your answer

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

More Coding questions