Interview Query

Data Stream Median

Start Timer

0:00:00

Upvote
4
Downvote
Save question
Mark as completed
View comments (6)
Next question

Write a function data_stream_median to calculate the new median from a stream of ordered integers and the new element which is not yet inserted into the stream.

The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, so the median is the mean of the two middle values.

Example:

new_value = 2
stream = [1, 2, 3, 4, 5, 6]
def data_stream_median(new_value, stream): -> 3
.
.
.
.
.


Comments

Loading comments