• 수포자 3명이 반복적인 패턴으로 문제를 찍음
• 정답과 비교해서 가장 많이 맞춘 사람(여러 명일 수 있음)의 번호를 리턴
👉 즉, 정답 배열과 각 사람의 패턴을 순서대로 비교해서 채점
→ 맞춘 개수 최대인 사람(들) 리턴
1. 각 수포자의 패턴을 배열로 저장
2. 정답 배열을 순회하면서
• 각 수포자 패턴과 비교
• % 패턴 길이로 순환 구조 맞춤
3. 가장 많이 맞춘 사람 찾기 → 리스트에 담기
import java.util.*;
class Solution {
public int[] solution(int[] answers) {
int[] p1 = {1, 2, 3, 4, 5};
int[] p2 = {2, 1, 2, 3, 2, 4, 2, 5};
int[] p3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5};
int[] scores = new int[3];
for (int i = 0; i < answers.length; i++) {
if (answers[i] == p1[i % p1.length]) scores[0]++;
if (answers[i] == p2[i % p2.length]) scores[1]++;
if (answers[i] == p3[i % p3.length]) scores[2]++;
}
int max = Math.max(scores[0], Math.max(scores[1], scores[2]));
List<Integer> result = new ArrayList<>();
for (int i = 0; i < 3; i++) {
if (scores[i] == max) {
result.add(i + 1); // 수포자 번호는 1부터 시작
}
}
// List를 배열로 변환
return result.stream().mapToInt(i -> i).toArray();
}
}