Bucket trades by quote regime
Asked at Two Sigma, Akuna
You have two time-sorted streams: quote-update timestamps quote_ts (each marks when a new quote took effect) and trade timestamps trade_ts. Each trade printed under exactly one prevailing quote, the quote that was live when it executed. Count how many trades fall into each quote regime: the half-open interval [quote_ts[i], quote_ts[i+1]), plus a leading bucket for trades that printed before the first quote.
quote_ts = [2, 5, 9]
trade_ts = [1, 3, 4, 5, 7, 10, 11]
->
[1, 2, 2, 2]
# bucket 0 (before ts=2): {1} -> 1
# bucket 1 ([2, 5)): {3, 4} -> 2
# bucket 2 ([5, 9)): {5, 7} -> 2
# bucket 3 ([9, inf)): {10, 11} -> 2
Return the per-regime counts in , one pass over each stream.
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.