Easy · Streams & I/O

Find Kth largest in stream

Given an integer k 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

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Streams & I/O problems