05Maintain the running median of a number stream as values arrive.▼mediumGoogleMetaAmazon1 repliesunlockedA classic that pays off the two-heap insight. A sorted list costs O(n) per insert; 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 checks 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 shifts 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 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 →
42Find the k-th largest element (Quickselect).▼mediumGoogleMetaAmazon2 replies◆ premiumK-th largest has three textbook solutions, and what interviewers watch for 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 genuinely the better call. Here is the answer.Open full answer →
63Meeting Rooms II: minimum rooms for overlapping intervals.▼mediumGoogleMetaAmazon1 replies◆ premiumThe fewest meeting rooms you need equals the highest number of meetings active simultaneously. That reframing is the entire interview; two O(n log n) solutions drop out of it, and the tie-handling catches careless candidates.Open full answer →