ps | |
---|---|
링크 | programmers.co.kr/… |
출처 | 프로그래머스 |
문제 번호 | 72411 |
문제명 | 메뉴 리뉴얼 |
레벨 | Level 2 |
분류 |
구현 |
시간복잡도 | O(n*2^m) |
인풋사이즈 | n<=10, m<=20 |
사용한 언어 | Python |
해결날짜 | 2021/01/25 |
출처 |
ps:problems:programmers:2021_kakao_blind_recruitment |
"""Solution code for "Programmers 72411. 메뉴 리뉴얼".
- Problem link: https://programmers.co.kr/learn/courses/30/lessons/72411
- Solution link: http://www.teferi.net/ps/problems/programmers/72411
"""
import collections
import itertools
MAX_MENU_COUNT = 10
def solution(orders, course):
counter_by_size = [collections.Counter() for _ in range(MAX_MENU_COUNT + 1)]
for order in orders:
for i in range(2, len(order) + 1):
counter_by_size[i].update(itertools.combinations(sorted(order), i))
answer = []
for menu_count in course:
menus_and_count = counter_by_size[menu_count].most_common()
if menus_and_count and (max_count := menus_and_count[0][1]) >= 2:
for m, c in menus_and_count:
if c != max_count:
break
answer.append(''.join(m))
return sorted(answer)