You are viewing a single comment's thread. Return to all comments →
Python3 using bisect library
from bisect import bisect, insort def activityNotifications(expenditures, d): res = 0 vals = sorted(expenditures[:d]) for first_val, cur_val in zip(expenditures, expenditures[d:]): if d % 2: median2 = 2 * vals[d//2] else: median2 = vals[d//2] + vals[d//2-1] if cur_val >= median2: res += 1 vals.pop(bisect(vals, first_val) - 1) insort(vals, cur_val) return res
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 →
Python3 using bisect library