Skip to content
Optimal Lab

Practice · 5 problems

Heap / Priority Queue

0 of 5 solved on this device

Watch it first · interactiveHeap: top k of a stream →Read the explainer · optimal-roundWhen to use it, and its look-alikes ↗
  1. 091Last Stone WeightYou repeatedly smash the two heaviest stones together. If they are equal both are destroyed; otherwise the heavier one is left with the weight difference. Return the weight of the last remaining stone, or 0 if none remain.Easy
  2. 092Kth Largest Element in an ArrayGiven an integer array `nums` and an integer `k`, return the kth largest element. This is the kth largest in sorted ORDER, not the kth distinct element.Medium
  3. 093K Closest Points to OriginGiven an array of points on the plane and an integer `k`, return the k points closest to the origin (0, 0) by Euclidean distance. Any order is acceptable.Medium
  4. 094Find Median from Data StreamDesign a data structure supporting addNum(num) to ingest a stream of integers and findMedian() to return the median of everything seen so far. Implement the MedianFinder class.Hard
  5. 129Task SchedulerGiven an array of CPU `tasks` labelled A-Z and a cooldown `n`, identical tasks must be separated by at least n intervals. Each task takes one interval, and the CPU may idle. Return the minimum number of intervals needed to finish all tasks.Medium