Day70

강태훈·2026년 4월 10일

nbcamp TIL

목록 보기
70/97

알고리즘 코드카타

Average Time of Process per Machine

select machine_id, round(avg(timesum), 3) as processing_time
from (
    select a.machine_id, (b.timestamp - a.timestamp) as timesum
    from Activity a
    join Activity b
    on a.machine_id = b.machine_id
    and a.process_id = b.process_id 
    and a.activity_type like "start"
    and b.activity_type like "end"
) as timetable
group by machine_id
;

모의고사

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

class Solution {
    public int[] solution(int[] answers) {
        List<Integer> person1 = List.of(1, 2, 3, 4, 5);
        List<Integer> person2 = List.of(2, 1, 2, 3, 2, 4, 2, 5);
        List<Integer> person3 = List.of(3, 3, 1, 1, 2, 2, 4, 4, 5, 5);

        List<Integer> per1 = new ArrayList<>(pers(person1, answers));
        List<Integer> per2 = new ArrayList<>(pers(person2, answers));
        List<Integer> per3 = new ArrayList<>(pers(person3, answers));

        int[] score = {0, 0, 0};


        for (int i = 0; i < answers.length; i++) {
            int ans = answers[i];
            if (ans == per1.get(i)) {
                score[0]++;

            }
            if (ans == per2.get(i)) {
                score[1]++;

            }
            if (ans == per3.get(i)) {
                score[2]++;

            }
        }

        int max = Collections.max(Arrays.stream(score).boxed().collect(Collectors.toList()));

        List<Integer> scoreList = Arrays.stream(score).boxed().collect(Collectors.toList());
        List<Integer> result = new ArrayList<>();

        for (int i = 0; i < scoreList.size(); i++) {
            if (scoreList.get(i).equals(max)) {
                result.add(i + 1);
            }
        }

        return result.stream().mapToInt(Integer::intValue).toArray();
    }


    public List<Integer> pers(List<Integer> person, int[] answers) {
        List<Integer> pers = new ArrayList<>(person);

        while (pers.size() < answers.length) {
            pers.addAll(person);
        }

        return pers;
    }
}

0개의 댓글