We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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
Find the Running Median
You are viewing a single comment's thread. Return to all comments →
def runningMedian(a): # Write your code here sortedList = [] result = [] size = len(a) median = 0