Ok Garmin, save video

10s 256 MB
Exclusive Easy+ 2.5
BasicsData Structures Amazon

Implement 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 number
  • payload: an opaque value you should replay in order
Signature
Replayer(start_seq, max_buffer)
  • Initializes the replayer.
  • The next expected sequence number is start_seq.
  • max_buffer is the maximum number of distinct out-of-order sequence numbers that may be buffered at once.
Signature
push(seq, payload)
  • Adds an event (seq, payload) to the replayer.
  • Returns any payloads that became replayable as a result of this call, in increasing sequence order starting from the current expected sequence.
  • If the event’s seq is a duplicate of one already seen (buffered or already replayed), it must be ignored.
  • If buffering this event would cause the number of buffered distinct sequence numbers to exceed max_buffer, you must signal failure by printing error.
  • Payloads may only be returned when the replayer has a contiguous run beginning at the expected sequence. If it is not possible, print null.
  • After replaying sequence s, the next expected sequence becomes s + 1.
  • This is an incremental component, not a batch sorting task.
  • Correct handling of duplicates, gaps, and bounded buffering is required.
Example 1
Input
Replayer 5 3
push 6 b
push 8 d
push 5 a
push 7 c
Output
null
null
a b
c d
Accepted 25/58
Acceptance 43%
Loading editor...
Input
Replayer 5 3
push 6 b
push 8 d
push 5 a
push 7 c
Expected Output
null
null
a b
c d