Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class Solution {
  4.     public int[] solution(int[] answers) {
  5.         int[] student1 = {1, 2, 3, 4, 5};
  6.         int[] student2 = {2, 1, 2, 3, 2, 4, 2, 5};
  7.         int[] student3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5};
  8.         int length = answers.length;
  9.         int[] max = new int[3];
  10.  
  11.         for (int i = 0; i < length; i++) {
  12.             max[0] += answers[i] == student1[i % 5] ? 1 : 0;
  13.             max[1] += answers[i] == student2[i % 8] ? 1 : 0;
  14.             max[2] += answers[i] == student3[i % 10] ? 1 : 0;
  15.         }
  16.  
  17.         int currentMax = Math.max(Math.max(max[0], max[1]), max[2]);
  18.         List<Integer> answer = new ArrayList<>();
  19.  
  20.         for (int i = 0; i < 3; i++) {
  21.             if (currentMax == max[i]) {
  22.                 answer.add(i+1);
  23.             }
  24.         }
  25.  
  26.         return answer.stream().mapToInt(i -> i).toArray();
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement