Show a streamed message only if it does not repeat within 10 seconds.
Unlock detailed company stats for this questionUpgrade
You process a stream of messages arriving sequentially by timestamp, with a 10-second window. A message should be shown if and only if it does not appear twice within any 10-second window; if a message appears within 10 seconds of another instance of the exact same message, both instances are suppressed.
Input: struct Status { var timestamp: Int; var message: String } and func getNextStatus() -> Status. Implement showMessage(_ status: Status) to process the stream dynamically.
The stream is live, so you do not have the full input upfront. A future duplicate can invalidate a message that just arrived, so you must buffer or delay output until no duplicate can appear in its 10-second window.
Expect follow-ups like
- What is the memory footprint for an infinite stream?
- Can a sliding-window deque or doubly-linked list replace a full tracking map?
Community answers
No answers contributed by the community yet.


