Saturday, 1 May 2021

HIndex

 


//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

links for Data Structure

  1) 𝐁𝐞𝐜𝐨𝐦𝐞 𝐌𝐚𝐬𝐭𝐞𝐫 𝐢𝐧 𝐋𝐢𝐧𝐤𝐞𝐝 𝐋𝐢𝐬𝐭:  https://lnkd.in/gXQux4zj 2) 𝐀𝐥𝐥 𝐭𝐲𝐩𝐞𝐬 𝐨𝐟 𝐓𝐫𝐞𝐞 𝐓𝐫𝐚𝐯𝐞𝐫𝐬𝐚𝐥𝐬...