title: Fraudulent Activity Notifications Problem - reducing time complexity
body: <p>I am trying to solve a Sorting Problem in Python3 from HackerRank: <a href="https://www.hackerrank.com/challenges/fraudulent-activity-notifications/problem" rel="nofollow noreferrer">https://www.hackerrank.com/challenges/fraudulent-activity-notifications/problem</a></p>
  
  <p>This problem requires finding the median for every sub list on a running base.</p>
  
  <p>My code passes for the Sample Test Cases but not entirely for the actual Test Cases due to timeout termination. I suspect using sort() every time to find the median is causing the time lag.</p>
  
  <p>How can I improve my code?</p>
  
  <pre><code>def activityNotifications(expenditure, d):
      totalDays = len(expenditure)
      notified = 0
  
      for x in range(d, totalDays):
          check = expenditure[x-d:x]
          check.sort()
  
          if d % 2 == 0:
              median = (check[int(d/2)] + check[int((d-2)/2)])/2
          else:
              median = check[int((d-1)/2)]
  
          if expenditure[x] &gt;= median * 2:
              notified += 1
  
      return notified
  </code></pre>