코딩 테스트/Level 2

할인 행사

컴닥 2022. 10. 28. 00:01
반응형

https://school.programmers.co.kr/learn/courses/30/lessons/131127

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

def solution(want, number, discount):
    answer = 0
    to_buy = {a: b for a, b in zip(want, number)}
    for index in range(len(discount) - 9):
        temp = to_buy.copy()
        for each in discount[index:index + 10]:
            if each in temp:
                temp[each] -= 1
        if all(True if each <= 0 else False for each in temp.values()):
            answer += 1
    return answer
from collections import Counter


def solution(want, number, discount):
    answer = 0
    to_buy = Counter({a: b for a, b in zip(want, number)})
    for index in range(len(discount) - 9):
        temp = to_buy.copy() - Counter(discount[index:index + 10])
        if all(True if each <= 0 else False for each in temp.values()):
            answer += 1
    return answer
from collections import Counter
solution = lambda want, number, discount: sum(1 for index in range(len(discount) - 9) if all(True if each <= 0 else False for each in (Counter({a: b for a, b in zip(want, number)}) - Counter(discount[index:index + 10])).values()))
반응형