Example 1
Input
Replayer 5 3
push 6 b
push 8 d
push 5 a
push 7 cOutput
null
null
a b
c dImplement Replayer, a component that replays events in sequence order even when they arrive out of order.
This models a common infrastructure pattern: buffering, reordering, and bounded memory usage.
Each event has:
seq: a sequence numberpayload: an opaque value you should replay in orderReplayer(start_seq, max_buffer)start_seq.max_buffer is the maximum number of distinct out-of-order sequence numbers that may be buffered at once.push(seq, payload)(seq, payload) to the replayer.seq is a duplicate of one already seen (buffered or already replayed), it must be ignored.max_buffer, you must signal failure by printing error.null.s, the next expected sequence becomes s + 1.Replayer 5 3
push 6 b
push 8 d
push 5 a
push 7 cnull
null
a b
c dReplayer 5 3
push 6 b
push 8 d
push 5 a
push 7 cnull
null
a b
c d