Back to problems

Track the Running Median of an Integer Stream

Algorithm · Google · Medium

Implement runningMedianTwice(values), which returns a list of integers with exactly one result for each element in values. Think of the elements seen so far as a sorted multiset. If the current prefix has odd length, let m be its single middle element and append 2 * m. If the current prefix has even length, let a and b be its two middle elements and append a + b. Process values in the given order, computing this doubled median after every new element is added, and collect…

Checking your access…