Quant Memo
Coding/●●●●●

First order id the feed re-sends

After a reconnect your feed can replay events, and you want an early warning: as you read the stream once, report the first order_id whose second copy shows up. "First" means the earliest point in the stream at which any id is seen for the second time, not the id with the smallest value.

stream = [101, 102, 103, 102, 101]
-> 102          # 102's second copy (index 3) arrives before 101's (index 4)

Return the first id to repeat, or a sentinel if every id is unique. Aim for O(1)O(1) per event.

Your answer

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

More Coding questions