[HackerRank][Python3] Fraudulent Activity Notifications
2018. 7. 23. 22:02 |
프로그래밍/HackerRank
Problem :
https://www.hackerrank.com/challenges/fraudulent-activity-notifications/problem
My Solution :
#!/usr/bin/env python3 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 n, d = map(int, input().split()) expenditure = list(map(int, input().rstrip().split())) result = activityNotifications(expenditure, d) print(result)
'프로그래밍 > HackerRank' 카테고리의 다른 글
[HackerRank][Python3] Dijkstra: Shortest Reach 2 (0) | 2018.08.07 |
---|---|
[HackerRank][Python3] Tries: Contacts (0) | 2018.08.05 |
[HackerRank][Python3] Swap Nodes [Algo] (0) | 2018.07.27 |
[HackerRank][Python3] Special Palindrome Again (0) | 2018.07.23 |
[HackerRank][Python3] Merge Sort: Counting Inversions (0) | 2018.07.22 |
[HackerRank][Python3] Roads and Libraries (0) | 2018.07.22 |
[HackerRank][Python3] BFS: Shortest Reach in a Graph (0) | 2018.07.22 |
[HackerRank][Python3] Find the nearest clone (0) | 2018.07.22 |
최근에 달린 댓글 최근에 달린 댓글