-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfradulent_2.py
More file actions
32 lines (30 loc) · 812 Bytes
/
fradulent_2.py
File metadata and controls
32 lines (30 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def get_double_median(counter, d):
count = 0
for i in range(201):
count += counter[i]
if count > d//2:
break
if d % 2 == 1:
return 2 * i
else:
for left in range(i, -1, -1):
count -= counter[left]
if count < d//2:
return left + i
return 2 * i
def activityNotifications(expenditure, d):
count = 0
counter = [0]*201
for exp in expenditure[:d]:
counter[exp] += 1
for i in range(d, len(expenditure)):
new = expenditure[i]
old = expenditure[i-d]
double_median = get_double_median(counter, d)
if new >= double_median:
count += 1
if new == old:
continue
counter[new] += 1
counter[old] -= 1
return count