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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Data Structures
  3. Heap
  4. Find the Running Median
  5. Discussions

Find the Running Median

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • imaraovie
    4 months ago+ 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
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy