본문 바로가기

CodingTest/Level1

[연습] 코딩테스트- 실패율

코딩테스트 연습

  • programmers.co.kr
  • 2019 KAKAO BLIND RECRUITMENT
  • 실패율



import collections

def solution(n, stages):
    fail_p = {}
    stages.sort()
    col = collections.Counter(stages)
    for x,y in zip(list(col), list(col.values())):
        if x >= n+1:
            continue
        fail_p[x] = y / len(stages)
        for i in range(y):
            stages.pop(0)

    s = sorted(fail_p.items(), key = lambda x: x[1], reverse=True)
    answer = [x[0] for x in s]

    if n >= 1 and len(answer) != n:
        for x in range(n+1)[1:]:
            if answer.count(x) == 0:
                answer.append(x)

    #print(answer)
    return answer
반응형