코딩테스트 연습

개인정보 수집 유효기간(2023 KAKAO BLIND RECRUITMENT)

코딩초보ran 2023. 11. 16. 11:49

문제설명

제한사항

입출력 예 및 설명

 

 

문제풀이1

import pandas as pd
import datetime

def solution(today, terms, privacies):
    answer = []
    idx = 0

    dict = {}
    for t in terms:
        dict[t[0]] = t[2:]
    for priv in privacies:
        idx += 1
        
        수집일자, 약관코드 = pd.to_datetime(priv[0:10]), priv[11:]
        오늘일자 = pd.to_datetime(today)

        y, m, d = 수집일자.year, 수집일자.month, 수집일자.day
        ty, tm, td = 오늘일자.year, 오늘일자.month, 오늘일자.day

        priv_day = (y-1)*12*28 + (m-1)*28 + d
        to_day = (ty-1)*12*28 + (tm-1)*28 + td
        avaliable_day = int(dict[약관코드]) * 28
        
        del_day = priv_day + avaliable_day - 1
        
        
        if del_day < to_day:
            answer.append(idx)
        
    return answer

 

다른 사람의 풀이를 보고 오니, 날짜를 str[:5] 이런식으로 슬라이싱을 할 필요가 없다. 날짜가 2021.05.20 이런 형태로 들어오니까 '.' 을 기준으로 split를 하면 된다! 나는 슬라이싱을 하기 싫어서 timestamp로 바꿔서 year, month, day 을 추출함. 

 

 

채점결과

시간도 오래걸리고~ 용량도 많이 잡고~~


다른 사람 풀이

def to_days(date):
    year, month, day = map(int, date.split("."))
    return year * 28 * 12 + month * 28 + day

def solution(today, terms, privacies):
    months = {v[0]: int(v[2:]) * 28 for v in terms}
    today = to_days(today)
    expire = [
        i + 1 for i, privacy in enumerate(privacies)
        if to_days(privacy[:-2]) + months[privacy[-1]] <= today
    ]
    return expire

채점결과

 

이 풀이가 훨씬 효율적이다!!