Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 1차원 DP
- 2차원 dp
- 99클럽
- @BeforeAll
- @BeforeEach
- @Builder
- @Entity
- @GeneratedValue
- @GenericGenerator
- @NoargsConstructor
- @Query
- @Table
- @Transactional
- Actions
- Amazon EFS
- amazon fsx
- Android Studio
- ANSI SQL
- api gateway 설계
- api gateway 필터
- ApplicationEvent
- assertThat
- async/await
- AVG
- AWS
- aws eks
- AWS 프리티어
- Azure
- bind
- bitnami kafka
Archives
- Today
- Total
기록
프로그래머스_python_메뉴 리뉴얼 본문
문제
https://programmers.co.kr/learn/courses/30/lessons/72411
코딩테스트 연습 - 메뉴 리뉴얼
레스토랑을 운영하던 스카피는 코로나19로 인한 불경기를 극복하고자 메뉴를 새로 구성하려고 고민하고 있습니다. 기존에는 단품으로만 제공하던 메뉴를 조합해서 코스요리 형태로 재구성해서
programmers.co.kr
풀이
1. 조건에 맞는 메뉴 조합 만들기
2. 메뉴 조합별 빈도 세기
코드
from itertools import combinations
from collections import defaultdict
def solution(orders, course):
answer = list()
for count in course :
menu_items = list()
# 메뉴 구성 만들기
for food in orders :
if len(food)>=count :
combination_item = combinations(food, count)
menu_string = ["".join(sorted(it)) for it in combination_item]
menu_items.extend(menu_string)
# 빈도 세기
freqDict = defaultdict(set)
max_freq = 1
for item in set(menu_items) :
item_count = menu_items.count(item)
freqDict[item_count].add(item)
max_freq = max(max_freq, item_count)
# 최소 2명 이상의 손님에게서 주문된 구성만 코스요리 후보에 들어감
if max_freq>=2 : answer.extend(freqDict[max_freq])
return sorted(answer)
'코딩테스트 > python' 카테고리의 다른 글
프로그래머스_python_오픈채팅방 (0) | 2022.02.23 |
---|---|
프로그래머스_python_문자열압축 (0) | 2022.02.14 |
프로그래머스_python_파괴되지 않은 건물 (0) | 2022.02.08 |
프로그래머스_python_[1차] 추석 트래픽 (0) | 2022.02.07 |
프로그래머스_python_징검다리 건너기 (0) | 2022.02.03 |
Comments