-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFind H-index
51 lines (41 loc) · 1.19 KB
/
Find H-index
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//Find H-index
import java.io.*;
import java.util.*;
class GFG {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int test_cases = Integer.parseInt(br.readLine().trim());
while(test_cases-- > 0) {
String[] input = br.readLine().trim().split(" ");
int[] arr = new int[input.length];
for(int i = 0; i < input.length; i++) {
arr[i] = Integer.parseInt(input[i]);
}
Solution ob = new Solution();
int result = ob.hIndex(arr);
System.out.println(result);
System.out.println("~");
}
}
}
class Solution {
public int hIndex(int[] citations) {
int n = citations.length;
int[] freq = new int[n + 1];
for(int i = 0; i < n; i++) {
if(citations[i] >= n) {
freq[n] += 1;
}
else {
freq[citations[i]] += 1;
}
}
int idx = n;
int s = freq[n];
while(s < idx) {
idx--;
s += freq[idx];
}
return idx;
}
}