from itertools import combinations
from collections import Counter
def solution(orders, course):
answer = []
# 각 주문에서 가능한 모든 조합을 찾습니다.
possible_combinations = []
for order in orders:
for c in course:
possible_combinations.extend(combinations(sorted(order), c))
# 각 조합의 빈도수를 계산합니다.
frequency = Counter(possible_combinations)
# 각 코스 요리 크기에 대해 가장 빈도수가 높은 조합을 찾습니다.
for c in course:
most_common = [f for f in frequency.most_common() if len(f[0]) == c]
if most_common:
max_frequency = most_common[0][1]
if max_frequency >= 2: # 최소 2명 이상의 손님으로부터 주문된 경우
answer.extend([''.join(f[0]) for f in most_common if f[1] == max_frequency])
return sorted(answer)
사실 내가 풀어내지 못했다.
그 이유는 문제를 제대로 해석하지 못했다.
가능한 모든 경우를 다뤄야 했는데 나는 놓치는 경우가 있었다.
따라서 가능한 모든 경우를 위와 같이 구하는 것이라고 암기해야겠다.
카카오 구현 문제는 조건이 많을 뿐, 제대로 해석해서 접근하면 풀어낼 수 있다.
중요한 점은 문제를 처음에 제대로 해석해내는 것이다.
그리고 그 조건을 내가 완벽하게 이해했는지 파악해야 한다.