Code Room
CodingEasycod-g345
Subject Priority queuesLevel Entry–Mid~15 minCommon in Distributed systems · Algorithms & data structures interviewsIndustries Software development

Question

Maintain the k-th largest element in a stream. Process ops of the form ['add', x]; after each add, if at least k elements have been seen, report the current k-th largest value, otherwise report -1. Return the list of reported values, one per 'add'. k >= 1.

Implement
kth_largest_stream(k: int, ops: list[list]) → list[int]
Examples
in[3,[["add",4],["add",5],["add",8],["add",2],["add",3],["add",5],["add",10],["add",9],["add",4]]]out[-1,-1,4,4,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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.