forked from onlybooks/python-algorithm-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
7.py
28 lines (23 loc) · 897 Bytes
/
7.py
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
import datetime
def solution(lines: str) -> int:
# 로그의 시작, 종료 시각 저장
combined_logs = []
for log in lines:
logs = log.split(' ')
timestamp = datetime.datetime.strptime(logs[0] + ' ' + logs[1], "%Y-%m-%d %H:%M:%S.%f").timestamp()
combined_logs.append((timestamp, -1))
combined_logs.append((timestamp - float(logs[2][:-1]) + 0.001, 1))
accumulated = 0
max_requests = 1
combined_logs.sort(key=lambda x: x[0])
for i, elem1 in enumerate(combined_logs):
current = accumulated
# 1초 미만 윈도우 범위 요청 수 계산
for elem2 in combined_logs[i:]:
if elem2[0] - elem1[0] > 0.999:
break
if elem2[1] > 0:
current += elem2[1]
max_requests = max(max_requests, current)
accumulated += elem1[1]
return max_requests