반응형
https://school.programmers.co.kr/learn/courses/30/lessons/42889
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제풀이
해쉬와 비교함수를 이용하는게 핵심
from collections import Counter
from functools import cmp_to_key
def solution(N, stages):
stage = Counter(stages) # 분자
m = len(stages) # 분모
# 실패율 구하기
failure = {}
for i in range(1, N + 1):
m -= stage[i - 1]
if m != 0:
failure[i] = stage[i] / m
else:
failure[i] = 0
# 실패율 기준 내림차 정렬
sorted_failure = sorted(failure.items(), key=cmp_to_key(cmp))
# 출력 결과에 맞게 변환
answer = [item[0] for item in sorted_failure]
return answer
def cmp(x, y):
return y[1] - x[1]