05Maintain the running median of a number stream as values arrive.▼mediumGoogleMetaAmazon1 repliesunlockedA classic that rewards the two-heap insight. A sorted list gives O(n) inserts; two balanced heaps give O(log n) insert and O(1) median. Here is the implementation and the rebalancing detail people get wrong.Open full answer →
11Return the k most frequent elements in a large array (and handle a stream).▼medium★ EssentialMetaAmazonGoogle1 replies○ sign inA classic that tests whether you reach past sorting for the right structure. The signal is the heap solution (O(n log k)), the bucket-sort O(n) trick, and how it changes for an unbounded stream. Here is the answer.Open full answer →
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 →
42Find the k-th largest element (Quickselect).▼mediumGoogleMetaAmazon2 replies◆ premiumK-th largest has three textbook solutions, and the signal is knowing Quickselect's average O(n) beats sorting's O(n log n), why its worst case is O(n²), and when a heap is actually the better call. Here is the answer.Open full answer →
63Meeting Rooms II: minimum rooms for overlapping intervals.▼mediumGoogleMetaAmazon1 replies◆ premiumThe minimum number of meeting rooms equals the peak number of meetings running at once. The reframing is the whole interview; two O(n log n) solutions fall out of it, and the tie-handling trips up the careless.Open full answer →