목차

메뉴 리뉴얼

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)