Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class Solution {
- public int[] solution(int[] answers) {
- int[] student1 = {1, 2, 3, 4, 5};
- int[] student2 = {2, 1, 2, 3, 2, 4, 2, 5};
- int[] student3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5};
- int length = answers.length;
- int[] max = new int[3];
- for (int i = 0; i < length; i++) {
- max[0] += answers[i] == student1[i % 5] ? 1 : 0;
- max[1] += answers[i] == student2[i % 8] ? 1 : 0;
- max[2] += answers[i] == student3[i % 10] ? 1 : 0;
- }
- int currentMax = Math.max(Math.max(max[0], max[1]), max[2]);
- List<Integer> answer = new ArrayList<>();
- for (int i = 0; i < 3; i++) {
- if (currentMax == max[i]) {
- answer.add(i+1);
- }
- }
- return answer.stream().mapToInt(i -> i).toArray();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement