Find the Running Median

  • + 0 comments

    def runningMedian(a): # Write your code here sortedList = [] result = [] size = len(a) median = 0

    for i in range(size):
        num = a[i]
        bisect.insort(sortedList, num)
        n = len(sortedList)
        midIdx = n // 2
        if n % 2 == 0:
            median = (sortedList[midIdx] + sortedList[midIdx - 1]) / 2
        else:
            median = sortedList[midIdx]
    
        result.append(f'{median : .1f}')
    
    print(result)    
    return result