[파이썬] 프로그래머스 : 메뉴 리뉴얼 (Lv.2)
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
방향성 생각
코스요리로 만들 길이가 주어져있다.
주어진 주문에서 코스요리로 만들 길이의 조합들을 모두 꺼낸다.
메뉴 길이 중 주문량이 가장 많은 리스트들은 answer에 추가해준다.
from itertools import combinations as C
def solution(orders, course):
answer = []
for i in course:
table = {}
for order in orders:
temp = list(C(order,i))
for comb in temp:
comb = list(comb)
comb.sort()
s = ''.join(comb)
if s not in table: table[s] = 1
else : table[s] += 1
answer.extend([key for key,val in table.items() if val>=2 and val==max(table.values())])
answer.sort()
return answer
코멘트
카카오식 하란대로 구현하기
'Algorithm > etc' 카테고리의 다른 글
[파이썬] 프로그래머스 : 호텔 대실 (Lv.2) (0) | 2023.07.25 |
---|---|
[파이썬] 백준 28257: 알록달록 초콜릿 만들기 (골드3) (0) | 2023.07.20 |
[파이썬] 프로그래머스 : 순위 검색 (Lv.2) (0) | 2023.07.17 |
[파이썬] 프로그래머스 : 오픈채팅방 (Lv.2) (0) | 2023.07.15 |
[파이썬] 프로그래머스 : 파일명 정렬 (Lv.2) (0) | 2023.07.15 |
[파이썬] 프로그래머스 : 방문 길이 (Lv.2) (0) | 2023.07.11 |
[파이썬] 프로그래머스 : 테이블 해시 함수 (Lv.2) (0) | 2023.07.11 |
댓글