https://school.programmers.co.kr/learn/courses/30/lessons/118666
import java.util.*;
// 1: RT, 2:CF, 3: JM, 4: AN
class Solution {
public String solution(String[] survey, int[] choices) {
String answer = "";
String[] types = {"RT", "CF", "JM", "AN"};
HashMap<Character, Integer> hmap = new HashMap<>();
for (int i=0; i<survey.length; i++) {
char ch1 = survey[i].toCharArray()[0];
char ch2 = survey[i].toCharArray()[1];
if (choices[i] > 4) hmap.put(ch2, hmap.getOrDefault(ch2, 0) + choices[i] - 4);
else if (choices[i] < 4) hmap.put(ch1, hmap.getOrDefault(ch1, 0) + 4 - choices[i]);
}
for (String type : types) {
Character result = type.toCharArray()[0];
Integer score1 = hmap.getOrDefault(type.toCharArray()[0], 0);
Integer score2 = hmap.getOrDefault(type.toCharArray()[1], 0);
if (score1 == score2) {
if (result > type.toCharArray()[1]) {
result = type.toCharArray()[1];
}
} else if (score1 < score2) {
result = type.toCharArray()[1];
}
answer += result + "";
}
return answer;
}
}