Design a class that finds the kth largest element in a growing stream of numbers. It should support adding a new number and, after each addition, returning the current kth largest value seen so far.
k = 3, nums = [4,5,8,2]; add(3)4add(5); add(10)5, 5Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →A heap keeps the minimum (or maximum) element accessible in O(1), with O(log n) insert and remove. It's the tool whenever you repeatedly need "the smallest/largest remaining item" without needing everything fully sorted.
Read the full Heap / Priority Queue guide →
Original problem on LeetCode ↗