Code RoomRunning sum of k largest
MediumPrep Room Coding #469

Running sum of k largest

CodingDistributed systemsAlgorithms & data structuresEntry–Mid~15 min

Integers arrive one at a time from a stream. After each arrival, report the sum of the k largest values seen so far; while fewer than k values have arrived, report the sum of all of them. Return one total per arrival, in order. Values may repeat and may be negative. Example: nums = [3, 1, 5, 2], k = 2 gives [3, 4, 8, 8] — after the third arrival the two largest are 5 and 3, and the final 2 changes nothing.

Implement
running_top_k_sum(nums: list[int], k: int) → list[int]
Examples
in[[3,1,5,2],2]out[3,4,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 15 min
InputExpectedGot
[[3,1,5,2],2][3,4,8,8]not run yetsample