Find H | Java implementation of the above approach ; Function to find the H - index ; Set the range for binary search ; Check if current citations is possible ; Check to the right of mid ; Update h - index ; Since current value is not possible , check to the left of mid ; Print the h - index ; Driver Code ; citations
import java . io . * ; class GFG { static int hIndex ( int [ ] citations , int n ) { int hindex = 0 ; int low = 0 , high = n - 1 ; while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( citations [ mid ] >= ( mid + 1 ) ) { low = mid + 1 ; hindex = mid + 1 ; } else { high = mid - 1 ; } } System . out . println ( hindex ) ; return hindex ; } public static void main ( String [ ] args ) { int n = 5 ; int [ ] citations = { 5 , 3 , 3 , 2 , 2 } ; hIndex ( citations , n ) ; } }