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 →

  • eduardo_angel124
    2 months ago+ 0 comments

    this my solution but after the 2 case not working with more data :c help

    def runningMedian(a):
        # Write your code here
        res = []
        temp = []
        count =  0
        for number in a:
            temp.append(number)
            temp = sorted(temp)
            size  = len(temp)
            middle =  round(size / 2)
            impar = (size % 2)
    
            if(impar == 1):
                currentSize =  size -1 
                middleImpar =  round(currentSize / 2)
                median = temp[middleImpar]
                res.append(float(median))
            else:
                median =  (temp[middle -1] + temp[middle]) / 2
                res.append(float(median))
                
        return res
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy