정렬 후 upperbound, lowerbound로
분모는 전체 - lowerbound
분자는 upperbound - lowerbound
로 실패율 연산 후 최대힙으로 정렬
from bisect import bisect_left, bisect_right
from heapq import heappush, heappop
def solution(N, stages):
answer = []
stages = sorted(stages)
cnts = []
for i in range(1, N + 1):
left = bisect_left(stages, i)
right = bisect_right(stages, i)
total = len(stages) - left
failure_rate = (right - left) / total if total else 0
heappush(cnts, (-failure_rate, i))
while cnts:
answer.append(heappop(cnts)[1])
return answer
'practivceAlgorithm > programmers' 카테고리의 다른 글
[Programmers][Python] KAKAO 2018 프렌즈 4블록 (0) | 2021.10.31 |
---|---|
[Programmers][Python] KAKAO 2018 뉴스클러스터링 (0) | 2021.10.31 |
[Programmers][Python] KAKAO 2019 오픈채팅방 (0) | 2021.10.28 |
[Programmers][Python] Kakao 2019 후보키 (0) | 2021.10.28 |
[KAKAO 2021][Python] 순위 검색 (0) | 2021.10.24 |