2019 KAKAO BLIND RECRUITMENT - 실패율 (Level 1)

 

https://programmers.co.kr/learn/courses/30/lessons/42889


Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
from collections import Counter

def solution(N, stages):
    stages = Counter(stages)
    n_remained = [None] + [stages[idx_stage] if idx_stage in stages else 0 for idx_stage in range(1, N+2)]

    answer = []
    for idx_stage in range(1, N+1):
        elem = n_remained[idx_stage] / sum(n_remained[idx_stage:]) if n_remained[idx_stage] != 0 else 0
        answer.append((idx_stage, elem))

    answer.sort(key=lambda x: (x[1], -x[0]), reverse=True)
    answer = [i for i, e in answer]
    return answer

Complexity

$O(N \log N)$