programmers.co.kr/learn/courses/30/lessons/72411
코딩테스트 연습 - 메뉴 리뉴얼
레스토랑을 운영하던 스카피는 코로나19로 인한 불경기를 극복하고자 메뉴를 새로 구성하려고 고민하고 있습니다. 기존에는 단품으로만 제공하던 메뉴를 조합해서 코스요리 형태로 재구성해서
programmers.co.kr
[프로그래머스] 메뉴 리뉴얼 ( LEVEL 2 )
완전탐색 문제
menu_cnt 만큼의 크기로 모든 조합을 뽑고, 가장 많이 주문된 메뉴 조합을 찾으면 된다.
<파이썬 코드>
from itertools import combinations
from collections import Counter
def solution(orders, course):
answer = []
for menu_cnt in course:
tmp = []
for order in orders:
for c in combinations(order,menu_cnt):
tmp.append(''.join(sorted(c)))
most = Counter(tmp).most_common()
answer += [key for key, cnt in most if cnt>1 and cnt==most[0][1]]
return sorted(answer)
'PROGRAMMERS' 카테고리의 다른 글
[프로그래머스] 큰 수 만들기 (Level 2) (0) | 2021.04.21 |
---|---|
[프로그래머스] 입국심사 (Level 3) (0) | 2021.04.20 |
[프로그래머스] 소수찾기 (LEVEL 2) (0) | 2021.04.18 |
[프로그래머스] N으로 표현 (LEVEL 3) (0) | 2021.04.18 |
[프로그래머스] - 사칙연산 (LEVEL 4) (0) | 2021.03.19 |
댓글