from itertools import combinations
from collections import Counter
def solution(orders, course):
answer = []
for i in course:
candidates = []
for menu_li in orders:
for li in combinations(menu_li, i):
res = ''.join(sorted(li))
candidates.append(res)
sorted_candidates = Counter(candidates).most_common()
answer += [menu for menu, cnt in sorted_candidates if cnt > 1 and cnt == sorted_candidates[0][1]]
return sorted(answer)
orders = ["ABCFG", "AC", "CDE", "ACDE", "BCFG", "ACDEH"]
course = [2,3,4]
solution(orders, course)
'알고리즘 > 코딩테스트 기출' 카테고리의 다른 글
[카카오] 2021 신입공채 1차 코딩테스트 - 아이디 추천 (0) | 2021.06.22 |
---|
댓글