프로그래머스 lv1 실패율
1. 개요
2. 풀이
def solution(N, stages):
notCleared, reached = [0]*(N+2), [0]*(N+3)
failRate = [0]*(N+2)
for stage in stages:
notCleared[stage] += 1
reached[stage+1] -= 1
reached[0] += 1
# 누적합을 통해 도달한 숫자를 빠르게 구해보자
for i in range(1, N+2):
reached[i] += reached[i-1]
for i in range(N+2):
if reached[i]==0:
failRate[i] = 0
else:
failRate[i] = notCleared[i]/reached[i]
return sorted(range(1,N+1), key=lambda x: failRate[x], reverse=True)
Leave a comment