[Programmers] - 메뉴 리뉴얼 (Level 2)
2021 KAKAO BLIND RECRUITMENT
LEVEL : 2
문제링크
orders = ["ABCFG", "AC", "CDE", "ACDE", "BCFG", "ACDEH"]
course = [2,3,4]
def solution(orders, course):
answer = []
from itertools import combinations
for c in course:
dict = {}
for order in orders:
if len(order)>=c:
comb = list(combinations(order,c))
comb = [''.join(sorted(t)) for t in comb]
for com in comb:
if com not in dict.keys():
dict[com] =1
else:
dict[com] +=1
answer.extend([i for i in dict.keys() if dict[i] == max(dict.values()) and dict[i]>1])
return sorted(answer)
solution(orders, course)
['AC', 'ACDE', 'BCFG', 'CDE']
Comments