본문 바로가기
Algorithm/etc

[파이썬] 프로그래머스 : 메뉴 리뉴얼 (Lv.2)

by 베짱이28호 2023. 7. 15.

[파이썬] 프로그래머스 : 메뉴 리뉴얼 (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

코멘트

카카오식 하란대로 구현하기

댓글