[Programmers] - 신고 결과 받기 (Level 1)


2022 KAKAO BLIND RECRUITMENT
LEVEL : 1

문제 링크

def solution(id_list, report, k):

    report_dict = {}
    reported_num = {}

    for r in list(set(report)):
        r1 = r.split(" ")[0]
        r2 = r.split(" ")[1]

        if r1 in report_dict.keys():
            if isinstance(report_dict[r1],list):
                tmp = report_dict[r1]
                tmp.append(r2)
                report_dict[r1]= tmp
            else:
                tmp = [report_dict[r1]]
                tmp.append(r2)
                report_dict[r1] = tmp
        else:
            report_dict[r1]= r2

        if r2 in reported_num.keys():
            reported_num[r2] += 1
        else :
            reported_num[r2] = 1

    blacklist = [i for i in reported_num.keys() if reported_num[i] >= k]

    n_get_mail = {}
    for id in id_list:
        n = 0
        if id in report_dict.keys():
            if isinstance(report_dict[id],list):
                for rep in report_dict[id]:
                    if rep in blacklist:
                        n += 1
            else:
                if report_dict[id] in blacklist:
                        n += 1

        n_get_mail[id] = n

    answer = list(n_get_mail.values())

    return answer
id_list = ["muzi", "frodo", "apeach", "neo"]
report = ["muzi frodo","apeach frodo","frodo neo","muzi neo","apeach muzi"]
k = 2

solution(id_list, report, k)
[2, 1, 1, 0]

Comments