26Merge k sorted lists (or streams) efficiently.▼mediumGoogleMetaAmazon2 replies◆ premiumMerging k sorted sources is the canonical min-heap problem and a real data-engineering pattern (merging sorted shards/streams). The signal is the heap of k heads giving O(N log k). Here is the answer.Open full answer →
34Reservoir sampling: pick k random items from a stream of unknown length.▼mediumGoogleMetaAmazon2 replies◆ premiumSampling uniformly from a stream you cannot fit in memory (or whose length you never learn) is a real data-engineering problem. The signal is the replace-with-decreasing-probability trick and a proof that telescopes. Here is the answer.Open full answer →