Kth Largest Element in a Stream
Try to solve the Kth Largest Element in a Stream problem.
We'll cover the following
Statement
Given an infinite stream of integers (sorted or unsorted), nums
, design a class to find the largest element in a stream.
Note: It is the largest element in the sorted order, not the distinct element.
The class should have the following functions, inputs, and return values:
-
Init(nums, k): It takes an array of integers
nums
and an integerk
and initializes the class object. -
Add(value): It takes one integer
value
, appends it to the stream, and returns the element representing the largest element in the stream.
Constraints:
-
nums.length
-
nums[i]
-
value
- At most, calls will be made to add.
- It is guaranteed that there will be at least elements in the array when you search for the element.