Find K for every Array element such that at least K prefixes are â ‰¥ K | Function to find the K - value for every index in the array ; Multiset to store the array in the form of red - black tree ; Iterating over the array ; Inserting the current value in the multiset ; Condition to check if the smallest value in the set is less than it 's size ; Erase the smallest value ; h - index value will be the size of the multiset ; array ; Size of the array ; function call
function print_h_index ( arr , N ) { var ms = [ ] ; for ( var i = 0 ; i < N ; i ++ ) { ms . push ( arr [ i ] ) ; ms . sort ( ( a , b ) => a - b ) if ( ms [ 0 ] < ms . length ) { ms . shift ( ) ; } document . write ( ms . length + " " ) ; } } var arr = [ 9 , 10 , 7 , 5 , 0 , 10 , 2 , 0 ] ; var N = arr . length ; print_h_index ( arr , N ) ;