148. K-th Largest Element in a Stream (Array Variant)

HardArrayArray

Maintain the k-th largest element in a stream. Given k, an initial array, and a list of values to add one by one, return an array where each entry is the k-th largest element after that addition (or -1 if fewer than k elements exist). Input: 'k, [initial], [adds]'.

Input: 'k, [initial], [adds]'.

Output: Array of k-th largest values.

Examples

Example 1
Input: 3, [4,5,8,2], [3,5,10,9,4]
Output: [4,5,5,8,8]
Explanation: k-th largest after each add.
Example 2
Input: 1, [], [1,2,3]
Output: [1,2,3]
Explanation: Largest after each add.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →