Design a class to find the `k-th` largest element in a stream. Note that it is the `k-th` largest element in the sorted order, not the `k-th` distinct element. Implement `KthLargest` class: `KthLargest(int k, int[] nums)` Initializes the object with the integer `k` and the stream of integers `nums`. `int add(int val)` Appends the integer `val` to the stream and returns the element representing the `k-th` largest element in the stream.
Min-Heap of size K
To find the Kth largest element in a dynamic stream, we can use a min-priority queue (min-heap) to store only the `K` largest elements seen so far. In a min-heap of size `K`, the smallest element (at the root) is the Kth largest element of the entire stream. When a new element comes in, we add it to the heap and immediately remove the smallest element if the heap size exceeds `K`.