You are part of a university admissions office and need to keep track of the kth highest test score from applicants in real-time. This helps to determine cut-off marks for interviews and admissions dynamically as new applicants submit their scores. You are tasked with implementing a class KthLargest that, for a given integer k, maintains a stream of test scores and continuously returns the kth highest test score after a new score has been submitted. Implement the KthLargest class: - KthLargest(int k, int[] nums) Initializes the object with the integer k and the stream of test scores nums. - int add(int val) Adds a new test score val to the stream and returns the element representing the kth largest element in the pool of test scores so far.
Example 1
Input: operations = ["KthLargest","add","add","add","add","add"], arguments = [[3,[4,5,8,2]],[3],[5],[10],[9],[4]]
Output: [null,4,5,5,8,8]
Explanation: With k = 3 we track the 3 largest scores. Starting from [4,5,8,2]: add 3 → top three 4, 5, 8 → return 4. add 5 → 5, 5, 8 → 5. add 10 → 5, 8, 10 → 5. add 9 → 8, 9, 10 → 8. add 4 → still 8, 9, 10 → 8.
Example 2
Input: operations = ["KthLargest","add","add","add"], arguments = [[1,[]],[-3],[-2],[-4]]
Output: [null,-3,-2,-2]
Explanation: With k = 1 each call returns the largest score so far: -3, then -2, and -2 again because -4 is smaller.
Example 3
Input: operations = ["KthLargest","add","add"], arguments = [[2,[0]],[-1],[1]]
Output: [null,-1,0]
Explanation: With k = 2 and the stream [0]: adding -1 gives [0,-1], whose 2nd largest is -1. Adding 1 gives [1,0,-1], whose 2nd largest is 0.
Keep a min-heap holding only the k largest elements seen so far. Its smallest element (the heap root) is exactly the kth largest overall.
Run checks all cases above. Submit evaluates all test cases.