본문 바로가기
알고리즘/코딩테스트 기출

[카카오] 2021 신입공채 1차 코딩테스트 - 메뉴 리뉴얼

by 소꿍 2021. 6. 23.

 

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)

 

 

댓글