26Merge k sorted lists (or streams) efficiently.▼mediumGoogleMetaAmazon2 replies◆ premiumMerging k sorted sources is the textbook min-heap problem and a genuine data-engineering pattern (merging sorted shards/streams). Interviewers look for the heap of k heads yielding O(N log k). The answer follows.Open full answer →
34Reservoir sampling: pick k random items from a stream of unknown length.▼mediumGoogleMetaAmazon2 replies◆ premiumDrawing a uniform sample from a stream too large for memory (or whose length stays unknown) is a genuine data-engineering problem. What interviewers watch for: the replace-with-decreasing-probability trick and a telescoping proof. Here is the answer.Open full answer →