Code RoomKth largest stream
MediumPrep Room Coding #1151

Kth largest stream

CodingDistributed systemsAlgorithms & data structuresMid–Senior~20 min

Design a structure that, after being seeded with an initial list of integers, processes a stream of add operations and reports the kth largest value seen so far after each add. k is fixed at construction. Given k, the initial array, and a list of values to add in order, return the list of kth-largest results (one per add). It is guaranteed there are always at least k elements when a result is requested.

Implement
kth_largest_stream(k: int, initial: list[int], adds: list[int]) → list[int]
Examples
in[3,[4,5,8,2],[3,5,10,9,4]]out[4,5,5,8,8]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 20 min
InputExpectedGot
[3,[4,5,8,2],[3,5,10,9,4]][4,5,5,8,8]not run yetsample