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
|
257 Discussions
|
Please Login in order to post a comment
Easy C++ Solution using Heaps in O(nlog(n)) Time Complexity.
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.