Daily challenge for 2025-11-27
331. Kth Largest Element in a Stream
Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.
Implement solve(commands, inputs) which handles the class operations.
Operations:
- "KthLargest": Initializes the object with the integer k and the stream of integers nums.
- "add": Appends the integer val to the stream and returns the element representing the kth largest element in the stream.
Example:Input: commands = ["KthLargest", "add", "add", "add", "add", "add"], inputs = [[3, [4, 5, 8, 2]], [3], [5], [10], [9], [4]]Output: [null, 4, 5, 5, 8, 8]
Run this challenge interactively in Python or JavaScript when the app loads.