Algorithm · Stripe · Hard
Design and implement a Python streaming sampler that consumes an unbounded sequence of (user_id, event_time, event_type) tuples. For each distinct user_id, the sampler must keep at most M events, and the retained events must form a uniform random sample without replacement of all events observed for that user so far. Use reservoir sampling so that when a user has seen n events: if n M, every event has inclusion probability $$\frac{M}{n}$$. Provide a proof of correctness.…
Checking your access…