//https://www.youtube.com/watch?v=fVAR6SiATgI
public class HIndex {
public static void main(String[] args) {
//int arr[] = {3,1,2,3,2};//out put 2
int arr[] = {3,6,7,8,9}; //output 4 //bucket {0,0,0,1,0,4}
int bucket[] = new int[arr.length+1];
int n = arr.length;
for(int i=0;i<arr.length;i++){
if(arr[i]>=n){
bucket[n]++;
}else{
bucket[arr[i]]++;
}
}
int count = 0;
for(int i= bucket.length-1;i>=0;i--){
count = count+bucket[i];
if(count>=i){
System.out.println(i);
break;
}
}
}
}
No comments:
Post a Comment