class Solution {
public int[] solution(int N, int[] stages) {
int[] answer = new int[N];
int[] fail = new int[N+1];
double[] fRate = new double[N];
int players = stages.length;
for(int stage : stages) { fail[stage-1]++; }
for(int i=0; i<N; i++) {
if(players==0) { continue; }
fRate[i] = (double)fail[i]/players;
players -= fail[i];
}
for(int i=0; i<N; i++) {
double max = -1;
int index = 0;
for(int j=0; j<N; j++) {
if(fRate[j]>max) {
max = Math.max(fRate[j], max);
index = j;
}
}
fRate[index] = -2;
answer[i] = index+1;
}
return answer;
}
}