Solution: Kth Largest Element in a Stream
Let's solve the Kth Largest Element in a Stream problem using the Top K Elements pattern.
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 ...
Access this course and 1400+ top-rated courses and projects.