Created
February 1, 2021 11:26
-
-
Save inspirit941/d7d62df404c79c0ad90e19bf044bae45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import combinations | |
from collections import defaultdict | |
def solution(orders, course): | |
orders = [sorted(i) for i in orders] | |
counter = defaultdict(int) | |
max_count = defaultdict(int) | |
for order in orders: | |
for c in course: | |
if len(order) < c: | |
continue | |
# 단품메뉴의 모든 조합 확인 | |
combination = combinations(order, c) | |
for each in combination: | |
food = "".join(each) | |
# 조합 등장횟수 + 1 | |
counter[food] += 1 | |
# 조합갯수별 최댓값 확인 | |
if max_count[c] < counter[food]: | |
max_count[c] = counter[food] | |
answer = [] | |
for c in course: | |
# 조합갯수의 등장횟수가 2보다 작을 경우 pass | |
if max_count[c] < 2: continue | |
answer += [i[0] for i in counter.items() if len(i[0]) == c and i[1] == max_count[c]] | |
return sorted(answer) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment