Kth Largest Element in a Stream

Easy · Heap & Priority Queue · about 15 minutes

Asked at Amazon, Meta, Netflix.

Design a class that keeps track of the k-th largest score in a stream. KthLargest(k, nums) starts with the initial scores; add(val) adds a score and returns the current k-th largest. When add is called there are always at least k scores.

Related guides