Ok Garmin, save video

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.


Event Model

Each event has:

  • seq: a sequence number
  • payload: an opaque value you should replay in order

Constructor

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.

Methods

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.

Replay Rules

  • 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.

Notes

  • This is an incremental component, not a batch sorting task.
  • Correct handling of duplicates, gaps, and bounded buffering is required.

Examples

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 2/3
Acceptance 67%
Loading editor...
Sample Input:
Replayer 5 3 push 6 b push 8 d push 5 a push 7 c
Expected Output:
null null a b c d