Back to problems

Merge Multiple Timestamp-Sorted Event Streams

Algorithm · Amazon · Medium

You are given k event streams, each already ordered by non-decreasing timestamp. Build an iterator that combines them into a single stream in global chronological order. An event has the form [timestamp, payload]. When two or more events share the same timestamp, the output order must be deterministic: the event from the lower-numbered stream comes first, and events from the same stream keep the order in which they appear there. Memory is limited, so you must not load all…

Loading the rest of the question…