-
메뉴 리뉴얼코딩 테스트/Level 2 2021. 4. 7. 17:55반응형
메뉴 리뉴얼
2021 KAKAO BLIND RECRUITMENT 1971명 완료
programmers.co.kr/learn/courses/30/lessons/72411from itertools import combinations def solution(orders, course): answer = [] orders = [sorted(order) for order in orders] for course_size in course: temp = {} max_num = 0 for order in orders: for each in combinations(order, course_size): key = ''.join(each) temp[key] = temp.get(key, 0) + 1 if temp[key] > max_num: max_num = temp[key] for each in temp: if temp[each] > 1 and temp[each] == max_num: answer.append(each) return sorted(answer)
from collections import Counter from itertools import combinations def solution(orders, course): result = [] orders = [sorted(order) for order in orders] for course_size in course: order_combinations = [] for order in orders: order_combinations += combinations(order, course_size) most_ordered = 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)]
반응형