import java.io.*;
import java.util.Collections;
import java.util.PriorityQueue;
class Solution {
public int solution(int[] citations) {
PriorityQueue<Integer> pq = new PriorityQueue(Collections.reverseOrder());
for (Integer citation : citations) {
pq.add(citation);
}
int hIndex = 0;
while (!pq.isEmpty()) {
if (pq.peek() > hIndex) {
pq.poll();
hIndex++;
} else {
break;
}
}
return hIndex;
}
}