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.
I have tried my own python solution, but caught by timed out issues. How can this code be improved?
def activityNotifications(expenditure, d): #fraud
notify, n = 0, d//2
for i in range(len(expenditure)-d):
x=sorted(expenditure[i:i+d])
m=x[n] if d%2==1 else (x[n]+x[n+1])/2
if expenditure[i+d]>=2*m:
notify +=1
return notify
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Fraudulent Activity Notifications
You are viewing a single comment's thread. Return to all comments →
I have tried my own python solution, but caught by timed out issues. How can this code be improved?
def activityNotifications(expenditure, d): #fraud notify, n = 0, d//2 for i in range(len(expenditure)-d): x=sorted(expenditure[i:i+d]) m=x[n] if d%2==1 else (x[n]+x[n+1])/2 if expenditure[i+d]>=2*m: notify +=1 return notify