코드
from itertools import combinations
def solution(orders, course):
answer = []
res=[]
for o in orders:
for l in course:
o=''.join(sorted(o))
res+=list(combinations(o,l))
for l in course:
res_by_l=[i for i in res if len(i)==l and res.count(i)>=2]
if res_by_l:
max_m=max([res_by_l.count(j) for j in res_by_l])
for m in res_by_l:
if res_by_l.count(m)==max_m and ''.join(m) not in answer:
answer.append(''.join(m))
return sorted(answer)
다른 사람의 풀이
import collections
import itertools
def solution(orders, course):
result = []
for course_size in course:
order_combinations = []
for order in orders:
order_combinations += itertools.combinations(sorted(order), course_size)
most_ordered = collections.Counter(order_combinations).most_common()
result += [ k for k, v in most_ordered if v > 1 and v == most_ordered[0][1] ]
return [ ''.join(v) for v in sorted(result) ]