Easy · Streams & I/O
Find Kth largest in stream
Given an integer k ≥ 1 and an initial list of integers nums, build a stream object whose add(val) appends val and returns the kth largest value seen so far (duplicates count separately); at least k values are guaranteed to have been seen whenever add returns.
Examples
Example 1
k=3, init=[4,5], stream=[8,2,9]Output: [4, 4, 5]
Example 2
k=2, init=[3], stream=[1,4,1,5]Output: [1, 3, 3, 4]
Rebuild it in the studio
Open every published interview problem, solution, scene, and memory room free, with no account.