알고리즘/프로그래머스

[프로그래머스] 2022 KAKAO BLIND RECRUITMENT > 1. 신고 결과 받기

재담 2022. 2. 13. 20:34

문제 원본 : https://programmers.co.kr/learn/courses/30/lessons/92334

 

코딩테스트 연습 - 신고 결과 받기

문제 설명 신입사원 무지는 게시판 불량 이용자를 신고하고 처리 결과를 메일로 발송하는 시스템을 개발하려 합니다. 무지가 개발하려는 시스템은 다음과 같습니다. 각 유저는 한 번에 한 명의

programmers.co.kr

import java.util.Arrays;
import java.util.HashMap;

public class Solution {
    public int[] solution(String[] id_list, String[] report, int k) {
        int[] answer = new int[id_list.length];

        Arrays.sort(report);

        HashMap<String, Integer> map = new HashMap<>();
        for (int i = 0; i < report.length; ++i) {
            if (i > 0 && report[i].equals(report[i - 1])) {
                continue;
            }

            String[] spl = report[i].split(" ");
            if (map.get(spl[1]) == null) {
                map.put(spl[1], 1);
            } else {
                map.put(spl[1], map.get(spl[1]) + 1);
            }
        }

        for (int i = 0; i < report.length; ++i) {
            if (i > 0 && report[i].equals(report[i - 1])) {
                continue;
            }

            String[] spl = report[i].split(" ");
            if (map.get(spl[1]) >= k) {
                int idx = Arrays.asList(id_list).indexOf(spl[0]);
                ++answer[idx];
            }
        }

        return answer;
    }
}

 

  • 2022 카카오 블라인드 코딩 테스트 1번
  • 1번 문제답게 시키는대로 하면 되는 쉬운 문제