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.
Find the Running Median
Find the Running Median
Sort by
recency
|
256 Discussions
|
Please Login in order to post a comment
import math import os import random import re import sys
def runningMedian(a):
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')
I am surprised that I was able to get away with using a simple list structure (
vector
in C++). I started off with a simple, slow solution usingstd::sort
, and then when that didn't pass, I made sure to insert each incomingint
in the correct location. That was it. Not hard.Python3
import heapq import sys
def runningMedian(a):
if name == "main": input = sys.stdin.read().strip().split() n = int(input[0]) a = list(map(int, input[1:n+1])) medians = runningMedian(a) for median in medians: print(median)