Running median of stream

Write codeMedium16 min

Your task

A smart energy meter posts one integer power reading at a time. After each reading arrives, the dashboard wants the median of all readings received so far. To keep everything in integers, report each median doubled: for an odd count report 2 times the middle value; for an even count report the sum of the two middle values. Return the list of doubled medians, one per reading, in arrival order. Example: readings = [5, 2, 8] gives [10, 7, 10].

Examples

running_median_doubled(readings: list[int]) -> list[int]
Example 1
Inputrunning_median_doubled([5, 2, 8])
Output[10, 7, 10]